CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
时间: 2024-06-23 12:01:54 浏览: 277
CMAKE_CXX_COMPILER_ID "GNU" 是 CMake 中的一个条件语句,用于检查当前使用的 C++ 编译器是否为 GNU(GNU Compiler Collection)家族的一员,比如 GCC(GNU Compiler Collection)或 clang。当这个条件为真时,意味着你的项目配置是针对 GNU 编译器进行编译的。
CMake 使用这个标识符来确定编译选项、链接器和库等特定于特定编译器的行为。例如,如果你想为 GNU 编译器启用特定的优化选项或者使用 GNU 特有的链接器特性,你可以基于这个条件设置相应的 CMakeLists.txt 中的指令。
相关问题
CMAKE_MINIMUM_REQUIRED(VERSION 2.8) PROJECT(opencv_cl) SET(OPENCV_PATH /home/toybrick/rk3588_opencv) MESSAGE(STATUS "CMAKE_C_COMPILER:${CMAKE_C_COMPILER}") MESSAGE(STATUS "CMAKE_CXX_COMPILER:${CMAKE_CXX_COMPILER}") MESSAGE(STATUS "OPENCV_PATH:${OPENCV_PATH}") INCLUDE_DIRECTORIES(${OPENCV_PATH}/include/opencv4 ${OPENCV_PATH}/include) LINK_DIRECTORIES(${OPENCV_PATH}/lib /usr/lib/aarch64-linux-gnu/) SET(LINK_LIBS opencv_world mali pthread dl) ADD_EXECUTABLE(opencv_cl opencl_cs.cpp) TARGET_LINK_LIBRARIES(opencv_cl ${LINK_LIBS}) 在哪添加-Wl,-Bsymbolic
您可以在 SET 命令中设置变量 CMAKE_SHARED_LINKER_FLAGS,加上 -Wl,-Bsymbolic 选项即可。修改后的 CMakeLists.txt 如下:
```cmake
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(opencv_cl)
SET(OPENCV_PATH /home/toybrick/rk3588_opencv)
MESSAGE(STATUS "CMAKE_C_COMPILER:${CMAKE_C_COMPILER}")
MESSAGE(STATUS "CMAKE_CXX_COMPILER:${CMAKE_CXX_COMPILER}")
MESSAGE(STATUS "OPENCV_PATH:${OPENCV_PATH}")
INCLUDE_DIRECTORIES(${OPENCV_PATH}/include/opencv4 ${OPENCV_PATH}/include)
LINK_DIRECTORIES(${OPENCV_PATH}/lib /usr/lib/aarch64-linux-gnu/)
SET(LINK_LIBS opencv_world mali pthread dl)
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-Bsymbolic")
ADD_EXECUTABLE(opencv_cl opencl_cs.cpp)
TARGET_LINK_LIBRARIES(opencv_cl ${LINK_LIBS})
```
这样设置 CMAKE_SHARED_LINKER_FLAGS 后,链接器在链接时会尽可能使用本地符号,而不是全局符号,从而解决符号版本不兼容的问题。
mkdir -p build && cd build && cmake .. -- The C compiler identification is GNU 9.3.0 -- The CXX compiler identification is unknown -- Check for working C compiler: /work/bsp/rk356x/buildroot/output/rockchip_rk3568/host/bin/aarch64-buildroot-linux-gnu-gcc -- Check for working C compiler: /work/bsp/rk356x/buildroot/output/rockchip_rk3568/host/bin/aarch64-buildroot-linux-gnu-gcc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done CMake Error in CMakeLists.txt: No CMAKE_CXX_COMPILER could be found. Tell CMake where to find the compiler by setting either the environment variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path to the compiler, or to the compiler name if it is in the PATH. CMake Warning (dev) in CMakeLists.txt: No cmake_minimum_required command is present. A line of code such as cmake_minimum_required(VERSION 3.10) should be added at the top of the file. The version specified may be lower if you wish to support older CMake versions for this project. For more information run "cmake --help-policy CMP0000". This warning is for project developers. Use -Wno-dev to suppress it. -- Configuring incomplete, errors occurred! See also "/home/edu/workplace/yuenki/ykrecovery/build/CMakeFiles/CMakeOutput.log". See also "/home/edu/workplace/yuenki/ykrecovery/build/CMakeFiles/CMakeError.log". Makefile:7: recipe for target 'configure' failed make: *** [configure] Error 1
这是一个CMake的错误,它提示找不到C++编译器。建议你检查一下你的系统中是否安装了C++编译器,并确认它的路径是否正确。同时,你也可以通过设置环境变量CXX或者CMake缓存条目CMAKE_CXX_COMPILER来告诉CMake编译器的路径或者编译器名称。另外,CMakeLists.txt文件中还缺少cmake_minimum_required命令,你需要在文件的开头添加这个命令,以指定CMake的最低版本要求。
阅读全文