cmake error: string sub-command SUBSTRING requires four arguments
-
wrote on 23 Sept 2022, 11:57 last edited by TakC
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 saysCMakeLists.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}) [...]
-
wrote on 23 Sept 2022, 12:11 last edited by Paul Colby
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.
-
wrote on 23 Sept 2022, 12:45 last edited by
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. -
wrote on 23 Sept 2022, 12:56 last edited by TakC
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/4