Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. cmake error: string sub-command SUBSTRING requires four arguments
Forum Updated to NodeBB v4.3 + New Features

cmake error: string sub-command SUBSTRING requires four arguments

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
4 Posts 2 Posters 2.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TakC
    wrote on 23 Sept 2022, 11:57 last edited by TakC
    #1

    I am trying to get RInside implemented with Qt following the example available here. I am on macOS 12.6 using QT Creator 6.3.1.

    Setting up the make file for cmake requires me to do a number of operations on strings so that QT knows where to find the necessary header files.

    However, the line string(SUBSTRING ${RCPPFLAGS} ${NUM_TRUNC_CHARS} -1 RCPPFLAGS) throws an exception only inside of QT Creator, which says CMakeLists.txt:31: error: string sub-command SUBSTRING requires four arguments.

    If I cmake (v3.24.2) the project directly from a terminal it compiles without problems and creates the correct substring operations.

    Here is my CMakeLists.txt with some debug print statements.

    make_minimum_required(VERSION 3.5)
    
    project(rinside-clean LANGUAGES CXX)
    
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    add_executable(rinside-clean main.cpp)
    
    install(TARGETS rinside-clean
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
    
    # print function to debug
    function(PRINT_VAR VARNAME)
      message(STATUS "PRINT ${VARNAME}: ${${VARNAME}}")
    endfunction()
    
    execute_process(COMMAND R RHOME
                    OUTPUT_VARIABLE R_HOME)
    
    set(NUM_TRUNC_CHARS 2)
    
    execute_process(COMMAND R CMD config --cppflags
                    OUTPUT_VARIABLE RCPPFLAGS)
    
    PRINT_VAR(RCPPFLAGS)
    
    # this following line shows error: CMakeLists.txt:31: error: string sub-command SUBSTRING requires four arguments.
    string(SUBSTRING ${RCPPFLAGS} ${NUM_TRUNC_CHARS} -1 RCPPFLAGS)
    
    PRINT_VAR(RCPPFLAGS)
    PRINT_VAR(NUM_TRUNC_CHARS)
    
    include_directories(${RCPPFLAGS})
    
    [...]
    
    1 Reply Last reply
    0
    • P Offline
      P Offline
      Paul Colby
      wrote on 23 Sept 2022, 12:11 last edited by Paul Colby
      #2

      Hi @TakC,

      It's likel that either (or both) of ${RCPPFLAGS} and ${NUM_TRUNC_CHARS} are empty/unset. I'd suggest two things, depending on what suits your logic better.

      Quote the args, so they're seen as "present" even if empty, like:

      string(SUBSTRING "${RCPPFLAGS}" "${NUM_TRUNC_CHARS}" -1 RCPPFLAGS)
      

      And/or, put some conditional checks in before that line to handle when those variables are empty/unset.

      Cheers.

      1 Reply Last reply
      1
      • T Offline
        T Offline
        TakC
        wrote on 23 Sept 2022, 12:45 last edited by
        #3

        Thanks, it seems indeed as if the variables are not being set. This is odd, because both variables are always set when I run cmake for that project in my terminal. Only in Qt Creator it does not work.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          TakC
          wrote on 23 Sept 2022, 12:56 last edited by TakC
          #4

          Could there be any reason why the make file in Qt would not allow execute_process()?

          It seems none of my calls return the output variables with a value, e.g.
          execute_process(COMMAND R CMD config --cppflags OUTPUT_VARIABLE RCPPFLAGS).

          In the terminal again, this returns the correct value.

          1 Reply Last reply
          0

          1/4

          23 Sept 2022, 11:57

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved