opencv has been setup in my project but the imported c++ files are giving error
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
Build command failed.
Error while executing process C:\src\Android\Sdk\cmake\3.10.2.4988404\bin\ninja.exe with arguments {-C C:\Users\azad prajapat\AndroidStudioProjects\sunscape\sunscape\android\app.cxx\cmake\debug\armeabi-v7a native-panorama}
ninja: Entering directory `C:\Users\azad prajapat\AndroidStudioProjects\sunscape\sunscape\android\app.cxx\cmake\debug\armeabi-v7a'
[1/2] Building CXX object CMakeFiles/native-panorama.dir/src/main/jni/com_example_sunscape_NativePanorama.cpp.o
FAILED: CMakeFiles/native-panorama.dir/src/main/jni/com_example_sunscape_NativePanorama.cpp.o
C:\src\Android\Sdk\ndk\22.0.7026061\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi24 --gcc-toolchain=C:/src/Android/Sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=C:/src/Android/Sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/windows-x86_64/sysroot -Dnative_panorama_EXPORTS -I../../../../src/main/jniIncludes -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security -std=gnu++11 -Wno-error=format-security -frtti -fexceptions -stdlib=libstdc++ -O0 -fPIC -MD -MT CMakeFiles/native-panorama.dir/src/main/jni/com_example_sunscape_NativePanorama.cpp.o -MF CMakeFiles\native-panorama.dir\src\main\jni\com_example_sunscape_NativePanorama.cpp.o.d -o CMakeFiles/native-panorama.dir/src/main/jni/com_example_sunscape_NativePanorama.cpp.o -c ../../../../src/main/jni/com_example_sunscape_NativePanorama.cpp
In file included from ../../../../src/main/jni/com_example_sunscape_NativePanorama.cpp:3:
In file included from ../../../../src/main/jniIncludes\opencv2/opencv.hpp:52:
In file included from ../../../../src/main/jniIncludes\opencv2/core.hpp:52:
**../../../../src/main/jniIncludes\opencv2/core/cvdef.h:183:10: fatal error: 'limits' file not found
#include
1 error generated.**
ninja: build stopped: subcommand failed.
my cmake file
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++")
SET(CMAKE_EXE_LINKER_FLAGS "-lopencv_stitching")
include_directories(${CMAKE_SOURCE_DIR}/src/main/jniIncludes)
add_library(native-panorama
SHARED
src/main/jni/com_example_sunscape_NativePanorama.cpp)
add_library(lib_opencv SHARED IMPORTED)
set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/src/main/libs/${ANDROID_ABI}/libopencv_java4.so)
find_library(log-lib
log)
target_link_libraries(native-panorama ${log-lib} lib_opencv)
gradle file
externalNativeBuild {
cmake {
arguments "-DANDROID_TOOLCHAIN=clang++","-DANDROID_ARM_NEON=TRUE" ,"-DANDROID_STL_FORCE_FEATURES=OFF"
cppFlags "-std=gnu++11", "-Wno-error=format-security","-frtti -fexceptions"
}
}
ndk {
abiFilters 'x86', 'x86_64', 'armeabi-v7a',
'arm64-v8a'
}
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libstdc++")
Don't do that.
Related
I am trying to program an ARM STM32F407 on an STM32F4Discovery board. First, I built a project with OpenCM3 + CMakeLists.txt. It worked! The LED flashed. ;-) Now, I'm trying to make the same project with OpenCM3 + FreeRTOS + CMakeLists.txt. Is not working! :-( It is not able to link xTaskCreate and vTaskDelay.
Please can anyone see where I'm going wrong?
I got my FreeRTOSConfig.h from here.
Below I show the error messages and my CMakeLists.txt file.
[100%] Linking C executable TesteRTOS.elf
/usr/local/Cellar/arm-none-eabi-gcc/10.3-2021.07/gcc/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld: CMakeFiles/TesteRTOS.dir/src/Teste.c.o: in function `GreenLEDTask':
Teste.c:(.text.GreenLEDTask+0x16): undefined reference to `vTaskDelay'
/usr/local/Cellar/arm-none-eabi-gcc/10.3-2021.07/gcc/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld: CMakeFiles/TesteRTOS.dir/src/Teste.c.o: in function `main':
Teste.c:(.text.main+0x20): undefined reference to `xTaskCreate'
/usr/local/Cellar/arm-none-eabi-gcc/10.3-2021.07/gcc/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld: Teste.c:(.text.main+0x24): undefined reference to `vTaskStartScheduler'
collect2: error: ld returned 1 exit status
make[2]: *** [TesteRTOS.elf] Error 1
make[1]: *** [CMakeFiles/TesteRTOS.dir/all] Error 2
make: *** [all] Error 2
cmake_minimum_required(VERSION 3.13)
set(HAVE_FLAG_SEARCH_PATHS_FIRST 0)
set(CMAKE_C_COMPILER_WORKS 1)
set(CMAKE_CXX_COMPILER_WORKS 1)
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
project(TesteRTOS C CXX ASM)
set(PROJECT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(MCU_LINKER_SCRIPT ${PROJECT_DIR}/linkerscript.ld)
set(MCU_ROM_ADDRESS 0x08000000)
set(CPU_PARAMETERS
-mcpu=cortex-m4
-mthumb
-mfpu=fpv4-sp-d16
-mfloat-abi=hard
)
set(OPENCM3_COMPILER_FLAGS -DSTM32F4)
set(OPENCM3_MCU_LIB opencm3_stm32f4)
set(RTOS_PATH ~/Documents/STM32/FreeRTOS-Kernel)
set(RTOS_PORTABLE ARM_CM4F)
enable_language(C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
# Specify the cross compiler
SET(CMAKE_C_COMPILER /usr/local/bin/arm-none-eabi-gcc)
SET(CMAKE_CXX_COMPILER /usr/local/bin/arm-none-eabi-g++)
set(CMAKE_ASM_COMPILER /usr/local/bin/arm-none-eabi-gcc)
set(CMAKE_AR /usr/local/bin/arm-none-eabi-ar)
SET(CMAKE_OBJCOPY /usr/local/bin/arm-none-eabi-objcopy)
SET(CMAKE_SIZE /usr/local/bin/arm-none-eabi-size)
file(GLOB_RECURSE PROJECT_SOURCES FOLLOW_SYMLINKS
${PROJECT_DIR}/*.cpp
${PROJECT_DIR}/*.c
)
add_executable(${CMAKE_PROJECT_NAME}
${PROJECT_SOURCES}
)
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES
SUFFIX ".elf"
)
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE
$ENV{OPENCM3_PATH}/include
${PROJECT_DIR}
${RTOS_PATH}/include
)
FILE(GLOB FreeRTOS_src ${RTOS_PATH}/*.c)
add_library(FreeRTOS STATIC
${FreeRTOS_src}
${RTOS_PATH}/portable/GCC/${RTOS_PORTABLE}/port.c
${RTOS_PATH}/portable/MemMang/heap_4.c
)
target_include_directories(FreeRTOS PUBLIC
${RTOS_PATH}/include
${RTOS_PATH}/portable/GCC/${RTOS_PORTABLE}/
${PROJECT_DIR}
)
target_compile_options(FreeRTOS PRIVATE
${CPU_PARAMETERS}
${OPENCM3_COMPILER_FLAGS}
-Wall -Wextra -Wundef -Wshadow -Wredundant-decls
-fno-common -ffunction-sections -fdata-sections -MD
$<$<CONFIG:Debug>:-Og -g3 -ggdb>
$<$<CONFIG:Release>:-Og -g0>
)
target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE
${CPU_PARAMETERS}
${OPENCM3_COMPILER_FLAGS}
-Wall -Wextra -Wundef -Wshadow -Wredundant-decls
-fno-common -ffunction-sections -fdata-sections -MD
$<$<CONFIG:Debug>:-Og -g3 -ggdb>
$<$<CONFIG:Release>:-Og -g0>
)
target_link_options(${CMAKE_PROJECT_NAME} PRIVATE
--static -nostartfiles
--specs=nosys.specs
-T${MCU_LINKER_SCRIPT} -L$ENV{OPENCM3_PATH}/lib
${CPU_PARAMETERS}
-ggdb3 -Wl,-Map=${CMAKE_PROJECT_NAME}.map
-Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group
-Wl,--cref -Wl,--gc-sections
)
target_link_libraries(${CMAKE_PROJECT_NAME} ${OPENCM3_MCU_LIB} FreeRTOS)
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_SIZE} $<TARGET_FILE:${CMAKE_PROJECT_NAME}>)
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O ihex $<TARGET_FILE:${CMAKE_PROJECT_NAME}>
${CMAKE_PROJECT_NAME}.hex
COMMAND ${CMAKE_OBJCOPY} -O binary $<TARGET_FILE:${CMAKE_PROJECT_NAME}>
${CMAKE_PROJECT_NAME}.bin
COMMENT "Creating ${PROJECT_NAME}.bin and ${PROJECT_NAME}.hex."
)
add_custom_target(FLASH
st-flash --reset write ${PROJECT_NAME}.bin ${MCU_ROM_ADDRESS}
DEPENDS ${CMAKE_PROJECT_NAME}
COMMENT "Flashing ${PROJECT_NAME}"
)
I want to transfer an old side project to CMake. Previously it used a Makefile with custom variables, defines and etc. I specified the same flags to compile various configurations. I did it this way:
cmake_minimum_required(VERSION 3.2.2)
project(wise_RK)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(SOURCES main.cpp devices/RK.cpp LogWriter/LogWriter.cpp)
set(CMAKE_CXX_FLAGS "-DIMA -std=c++11 -Wall -Wextra -c -O2 -MMD -MP -MF '$#.d'")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
include_directories(
structs
devices
LogWriter
/home/data/lib/wise_versioning
/home/data/lib/wisenet
/home/data/lib/wise_log
/home/data/lib/wise_rs_device
/home/data/lib/json
)
# wise_rs_device
add_library(wise_rs_device STATIC IMPORTED GLOBAL)
set_target_properties(wise_rs_device PROPERTIES
IMPORTED_LOCATION "/home/data/lib/wise_rs_device/libwise_rs_device.a"
INTERFACE_INCLUDE_DIRECTORIES "/home/data/lib/wise_rs_device/"
)
# wisenet
add_library(wisenet STATIC IMPORTED GLOBAL)
set_target_properties(wisenet PROPERTIES
IMPORTED_LOCATION "/home/data/lib/wisenet/libwise_net_rs485.so"
INTERFACE_INCLUDE_DIRECTORIES "/home/data/lib/wisenet/"
)
#wise_log
add_library(wise_log STATIC IMPORTED GLOBAL)
set_target_properties(wise_log PROPERTIES
IMPORTED_LOCATION "/home/data/lib/wise_log/Release/GNU-Linux/libwise_log.so"
INTERFACE_INCLUDE_DIRECTORIES "/home/data/lib/wise_log/"
)
add_executable(wise_rk ${SOURCES})
target_link_libraries(wise_rk PRIVATE wise_rs_device wisenet wise_log)
add_definitions(-DSOME_IMPORTANT_DEFINITION)
-D is define of various configurations.
In the Makefile, the list of project object files (not libraries) involved in the assembly was like this:
OBJECTS:=$(shell find * -type f -name "*.cpp" | sed "s/\.cpp/\.o /" | sort)
DEPENDS:=$(addprefix build/$(CONF)/, ${OBJECTS:.o=.o.d})
-include ${DEPENDS}
When I built my CMake:
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/wise_rk.dir/link.txt --verbose=1
/usr/bin/c++ -DIMA -std=c++11 -Wall -Wextra -c -O2 -MMD -MP -MF '$#.d' CMakeFiles/wise_rk.dir/main.cpp.o CMakeFiles/wise_rk.dir/devices/RK.cpp.o CMakeFiles/wise_rk.dir/LogWriter/LogWriter.cpp.o -o wise_rk -rdynamic /home/data/lib/wise_rs_device/libwise_rs_device.a /home/data/lib/wisenet/libwise_net_rs485.so /home/data/lib/wise_log/Release/GNU-Linux/libwise_log.so
c++: warning: CMakeFiles/wise_rk.dir/main.cpp.o: linker input file unused because linking not done
c++: warning: CMakeFiles/wise_rk.dir/devices/RK.cpp.o: linker input file unused because linking not done
c++: warning: CMakeFiles/wise_rk.dir/LogWriter/LogWriter.cpp.o: linker input file unused because linking not done
c++: warning: /home/data/lib/wise_rs_device/libwise_rs_device.a: linker input file unused because linking not done
c++: warning: /home/data/lib/wisenet/libwise_net_rs485.so: linker input file unused because linking not done
c++: warning: /home/data/lib/wise_log/Release/GNU-Linux/libwise_log.so: linker input file unused because linking not done
make[2]: Leaving directory `/home/anzipex/Downloads/wise_RK/build'
/usr/local/bin/cmake -E cmake_progress_report /home/anzipex/Downloads/wise_RK/build/CMakeFiles 1 2 3
[100%] Built target wise_rk
make[1]: Leaving directory `/home/anzipex/Downloads/wise_RK/build'
/usr/local/bin/cmake -E cmake_progress_start /home/anzipex/Downloads/wise_RK/build/CMakeFiles 0
I do not know what to do next to solve this kind of problem.
I changed all the .so libs to SHARED. And also removed part of flags -c -O2 -MMD -MP -MF '$#.d' like #Botje wrote. Seems like project built.
When building a C++ executable under Linux using cmake 3.7, I see a -std=gnu++11 flag being added to compile flags. The problem is, I'm already manually adding a -std=c++1z flag, and this new one overwrites mine. This happens only for executables, but I cannot find this being mentioned in the docs. The CMAKE_CXX_STANDARD is empty, and setting the CXX_STANDARD property on the target has no effect. Is there a way to remove this flag?
This seems to be not only limited to executables.
Here's my (simplified) cmake:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z")
find_boost(serialization system)
find_package(Qt5Widgets REQUIRED)
link_directories(${Boost_LIBRARY_DIRS})
include_directories(
${Boost_INCLUDE_DIRS}
${ZMQ_INCLUDE_DIR}
${CPPZMQ_INCLUDE_DIR}
)
if(WIN32)
add_definitions(-DNOMINMAX)
endif()
add_executable(
${PROFILER_CLIENT_NAME}
main.cpp
MainWindow.cpp
MainWindow.h
ProfilerWidget.cpp
ProfilerWidget.h
TimelineWidget.cpp
TimelineWidget.h
ZmqReceiver.cpp
ZmqReceiver.h
)
add_dependencies(${PROFILER_CLIENT_NAME} boost zeromq)
target_link_libraries(
${PROFILER_CLIENT_NAME}
PRIVATE ${PROFILER_NAME}
PRIVATE ${Boost_LIBRARIES}
PRIVATE Qt5::Widgets
)
As #florian suspected, it's Qt5 that's polluting your compile commands. Using a similar CMakeLists.txt:
cmake_minimum_required(VERSION 3.7.2 FATAL_ERROR)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z")
set(BOOST_ROOT "/usr/local/opt/boost#1.55")
execute_process(COMMAND brew --prefix qt5
COMMAND tr -d \\n
OUTPUT_VARIABLE QT5_BREW_PATH)
find_package(Boost COMPONENTS serialization system)
find_package(Qt5 COMPONENTS Widgets HINTS ${QT5_BREW_PATH})
link_directories(${Boost_LIBRARY_DIRS})
include_directories(${Boost_INCLUDE_DIRS})
add_executable(foo main.cpp)
target_link_libraries(foo
PRIVATE ${Boost_LIBRARIES}
PRIVATE Qt5::Widgets
)
I configured and built a dummy executable. You can plainly see the -std=c++1z and the -std=gnu++11 on the compile line:
❯ make VERBOSE=1
/usr/local/Cellar/cmake/3.7.2/bin/cmake -H/Users/nega/foo -B/Users/nega/foo --check-build-system CMakeFiles/Makefile.cmake 0
/usr/local/Cellar/cmake/3.7.2/bin/cmake -E cmake_progress_start /Users/nega/foo/CMakeFiles /Users/nega/foo/CMakeFiles/progress.marks
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 all
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/foo.dir/build.make CMakeFiles/foo.dir/depend
cd /Users/nega/foo && /usr/local/Cellar/cmake/3.7.2/bin/cmake -E cmake_depends "Unix Makefiles" /Users/nega/foo /Users/nega/foo /Users/nega/foo /Users/nega/foo /Users/nega/foo/CMakeFiles/foo.dir/DependInfo.cmake --color=
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/foo.dir/build.make CMakeFiles/foo.dir/build
[ 50%] Building CXX object CMakeFiles/foo.dir/main.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_WIDGETS_LIB -I/usr/local/opt/boost#1.55/include -iframework /usr/local/opt/qt5/lib -isystem /usr/local/opt/qt5/lib/QtWidgets.framework/Headers -isystem /usr/local/opt/qt5/lib/QtGui.framework/Headers -isystem /System/Library/Frameworks/OpenGL.framework/Headers -isystem /usr/local/opt/qt5/lib/QtCore.framework/Headers -isystem /usr/local/opt/qt5/./mkspecs/macx-clang -std=c++1z -fPIC -std=gnu++11 -o CMakeFiles/foo.dir/main.cpp.o -c /Users/nega/foo/main.cpp
[100%] Linking CXX executable foo
/usr/local/Cellar/cmake/3.7.2/bin/cmake -E cmake_link_script CMakeFiles/foo.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -std=c++1z -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/foo.dir/main.cpp.o -o foo -L/usr/local/opt/boost#1.55/lib -Wl,-rpath,/usr/local/opt/boost#1.55/lib /usr/local/opt/boost#1.55/lib/libboost_serialization-mt.dylib /usr/local/opt/boost#1.55/lib/libboost_system-mt.dylib /usr/local/opt/qt5/lib/QtWidgets.framework/QtWidgets /usr/local/opt/qt5/lib/QtGui.framework/QtGui /usr/local/opt/qt5/lib/QtCore.framework/QtCore
[100%] Built target foo
/usr/local/Cellar/cmake/3.7.2/bin/cmake -E cmake_progress_start /Users/nega/foo/CMakeFiles 0
If you comment out the Qt5 usage in our CMakeLists.txt and configure and build again, you'll see the -std=gnu++11 disappear (along with the -fPIC which Qt is also adding).
CMakeLists.txt:
cmake_minimum_required(VERSION 3.7.2 FATAL_ERROR)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z")
set(BOOST_ROOT "/usr/local/opt/boost#1.55")
execute_process(COMMAND brew --prefix qt5
COMMAND tr -d \\n
OUTPUT_VARIABLE QT5_BREW_PATH)
find_package(Boost COMPONENTS serialization system)
#find_package(Qt5 COMPONENTS Widgets HINTS ${QT5_BREW_PATH})
link_directories(${Boost_LIBRARY_DIRS})
include_directories(${Boost_INCLUDE_DIRS})
add_executable(foo main.cpp)
target_link_libraries(foo
PRIVATE ${Boost_LIBRARIES}
# PRIVATE Qt5::Widgets
)
make output (abridged):
[...]
[ 50%] Building CXX object CMakeFiles/foo.dir/main.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -I/usr/local/opt/boost#1.55/include -std=c++1z -o CMakeFiles/foo.dir/main.cpp.o -c /Users/nega/foo/main.cpp
[100%] Linking CXX executable foo
/usr/local/Cellar/cmake/3.7.2/bin/cmake -E cmake_link_script CMakeFiles/foo.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -std=c++1z -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/foo.dir/main.cpp.o -o foo -L/usr/local/opt/boost#1.55/lib -Wl,-rpath,/usr/local/opt/boost#1.55/lib /usr/local/opt/boost#1.55/lib/libboost_serialization-mt.dylib /usr/local/opt/boost#1.55/lib/libboost_system-mt.dylib
[100%] Built target foo
[...]
Unfortunately, after some brief digging I couldn't see where Qt was setting -std=gnu++11 in its *Config.cmake files. It must be reaching into CMake more than just a few grep's could find. Maybe reading through cmake --trace will provide some insight.
Curiously though, what ever it's doing respects CXX_STANDARD. If we tweak our original CMakeLists.txt and configure and build again:
CMakeLists.txt (abridged):
cmake_minimum_required(VERSION 3.7.2 FATAL_ERROR)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z")
set(BOOST_ROOT "/usr/local/opt/boost#1.55")
execute_process(COMMAND brew --prefix qt5
[...]
make output (abridged):
[...]
[ 50%] Building CXX object CMakeFiles/foo.dir/main.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DQT_WIDGETS_LIB -I/usr/local/opt/boost#1.55/include -iframework /usr/local/opt/qt5/lib -isystem /usr/local/opt/qt5/lib/QtWidgets.framework/Headers -isystem /usr/local/opt/qt5/lib/QtGui.framework/Headers -isystem /System/Library/Frameworks/OpenGL.framework/Headers -isystem /usr/local/opt/qt5/lib/QtCore.framework/Headers -isystem /usr/local/opt/qt5/./mkspecs/macx-clang -std=c++1z -fPIC -std=gnu++14 -o CMakeFiles/foo.dir/main.cpp.o -c /Users/nega/foo/main.cpp
[100%] Linking CXX executable foo
/usr/local/Cellar/cmake/3.7.2/bin/cmake -E cmake_link_script CMakeFiles/foo.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -std=c++1z -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/foo.dir/main.cpp.o -o foo -L/usr/local/opt/boost#1.55/lib -Wl,-rpath,/usr/local/opt/boost#1.55/lib /usr/local/opt/boost#1.55/lib/libboost_serialization-mt.dylib /usr/local/opt/boost#1.55/lib/libboost_system-mt.dylib /usr/local/opt/qt5/lib/QtWidgets.framework/QtWidgets /usr/local/opt/qt5/lib/QtGui.framework/QtGui /usr/local/opt/qt5/lib/QtCore.framework/QtCore
[100%] Built target foo
[...]
You can see that the (Qt added) -fPIC -std=gnu++11 is now -fPIC -std=gnu++14. Unfortunately this won't help you until CMake 3.8.0 is released and its CXX_STANDARD/CMAKE_CXX_STANDARD will understand "C++17".
I'm trying to create a Cmake file to compile an old C++ proyect, but when I run the make command I have this compile error:
In file included from /home/leontes/Dropbox/Siadex_Planner_ROS/planner/src/pyAPI.cpp:23:0:
/usr/include/python2.7/structmember.h:40:5: error: ‘Py_ssize_t’ does not name a type
Py_ssize_t offset;
^
/usr/include/python2.7/structmember.h:88:24: error: expected constructor, destructor, or type conversion before ‘PyMember_Get’
PyAPI_FUNC(PyObject *) PyMember_Get(const char *, struct memberlist *, const char *);
^
/usr/include/python2.7/structmember.h:89:17: error: expected constructor, destructor, or type conversion before ‘PyMember_Set’
PyAPI_FUNC(int) PyMember_Set(char *, struct memberlist *, const char *, PyObject *);
^
/usr/include/python2.7/structmember.h:92:24: error: expected constructor, destructor, or type conversion before ‘PyMember_GetOne’
PyAPI_FUNC(PyObject *) PyMember_GetOne(const char *, struct PyMemberDef *);
^
/usr/include/python2.7/structmember.h:93:17: error: expected constructor, destructor, or type conversion before ‘PyMember_SetOne’
PyAPI_FUNC(int) PyMember_SetOne(char *, struct PyMemberDef *, PyObject *);
^
make[2]: *** [CMakeFiles/planner.dir/src/pyAPI.cpp.o] Error 1
make[1]: *** [CMakeFiles/planner.dir/all] Error 2
make: *** [all] Error 2
And that is a System Library from Python...
I fixed the old make what was included with the proyect and it works fine, but with the new one no.
And the Cmakelist.txt that I'm building is this:
cmake_minimum_required(VERSION 2.8.3)
project(planner)
#Set headers directory
include_directories(include ${PYTHON_INCLUDE_PATH})
#Set source files
file(GLOB SOURCES "src/*.cpp")
#Set python vars
#Compiler flags
execute_process(COMMAND python-config --cflags OUTPUT_VARIABLE PYTHON_CPPFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
#Libraries
execute_process(COMMAND python-config --libs OUTPUT_VARIABLE PYTHON_EXTRA_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
#Linker flags
execute_process(COMMAND python-config --ldflags OUTPUT_VARIABLE PYTHON_LDFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
#Concatenate the new flags with the old ones
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} ${PYTHON_CPPFLAGS})
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} ${PYTHON_LDFLAGS})
#Define preprocessor directives for debugger.cpp
if(EXISTS /usr/include/readline.h)
add_definitions(-DHAVE_LIBREADLINE)
add_definitions(-DHAVE_READLINE_H)
endif(EXISTS /usr/include/readline.h)
if(EXISTS /usr/include/readline/readline.h)
add_definitions(-DHAVE_LIBREADLINE)
add_definitions(-DHAVE_READLINE_READLINE_H)
endif(EXISTS /usr/include/readline/readline.h)
if(EXISTS /usr/include/history.h)
add_definitions(-DHAVE_READLINE_HISTORY)
add_definitions(-DHAVE_HISTORY_H)
endif(EXISTS /usr/include/history.h)
if(EXISTS /usr/include/readline/history.h)
add_definitions(-DHAVE_READLINE_HISTORY)
add_definitions(-DHAVE_READLINE_HISTORY_H)
endif(EXISTS /usr/include/readline/history.h)
#Define preprocessor directives for stacknode.cpp
add_definitions(-DUSE_AC3)
#add_definitions(-DUSE_PC2)
#add_definitions(-DUSE_PC2_CL)
#Add a binary executable
add_executable(planner nodes/planner.cpp ${SOURCES})
#And link it
target_link_libraries(planner python2.7 readline ${PYTHON_EXTRA_LIBS})
I'm missing something??
EDIT:
Command used to compile in the old 'make'
g++ -DHAVE_CONFIG_H -I. -I../.. -Wall -Iheaders -I../xmlrpc/headers -I/usr/include/python2.7 -I/usr/include/x86_64-linux-gnu/python2.7 -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -DPYTHON_FOUND -DWITH_XMLRPC -g -O2 -DBUFFER_STACK -MT sources/pyAPI.o -MD -MP -MF $depbase.Tpo -c -o sources/pyAPI.o sources/pyAPI.cpp &&\
Command used to compile in the new 'make'
/usr/bin/c++ -DHAVE_LIBREADLINE -DHAVE_READLINE_HISTORY -DHAVE_READLINE_HISTORY_H -DHAVE_READLINE_READLINE_H -DUSE_PC2_CL -I/usr/include/python2.7 -I/usr/include/x86_64-linux-gnu/python2.7 -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -I/home/leontes/Dropbox/Siadex_Planner_ROS/planner/include -I/usr/include/python2.7 -o CMakeFiles/planner.dir/src/pyAPI.cpp.o -c /home/leontes/Dropbox/Siadex_Planner_ROS/planner/src/pyAPI.cpp
When using clang++, how can I make CMake use the -std=c++0x flag when compiling, but not when linking?
There are several other posts regarding using clang as compiler, but I have not found any hints on setting the c++ standard.
Here is what I tried:
CMakeLists.txt:
project(test)
add_executable(main main.cxx)
ClangOverride.txt:
SET (CMAKE_C_FLAGS_INIT "-Wall -std=c99")
SET (CMAKE_C_FLAGS_DEBUG_INIT "-g")
SET (CMAKE_C_FLAGS_MINSIZEREL_INIT "-Os -DNDEBUG")
SET (CMAKE_C_FLAGS_RELEASE_INIT "-O3 -DNDEBUG")
SET (CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-O2 -g")
SET (CMAKE_CXX_FLAGS_INIT "-Wall -std=c++0x -stdlib=libc++")
SET (CMAKE_CXX_FLAGS_DEBUG_INIT "-g")
SET (CMAKE_CXX_FLAGS_MINSIZEREL_INIT "-Os -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELEASE_INIT "-O3 -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-O2 -g")
SET (CMAKE_EXE_LINKER_FLAGS_INIT "")
main.cxx:
int main(){ return 0; }
Command used to invoke cmake
CC=clang CXX=clang++ cmake .. -DCMAKE_USER_MAKE_RULES_OVERRIDE=ClangOverride.txt -DCMAKE_BUILD_TYPE=Release
Building the project:
VERBOSE=1 make
This will invoke the following two commands:
/usr/bin/clang++ -Wall -std=c++0x -stdlib=libc++ -O3 -DNDEBUG -o CMakeFiles/main.dir/main.cxx.o -c /tmp/asdf/main.cxx
/usr/bin/clang++ -Wall -std=c++0x -stdlib=libc++ -O3 -DNDEBUG CMakeFiles/main.dir/main.cxx.o -o main -rdynamic
The second command results in warning because if the un-used flag: -std=c++0x
clang: warning: argument unused during compilation: '-std=c++0x'
CMakeFiles/main.dir/main.cxx.o: file not recognized: File format not recognized
clang: error: linker command failed with exit code 1 (use -v to see invocation)
How can I avoid this?
Use ADD_DEFINITIONS("-std=c++0x") instead of setting CXX flags.