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
时间: 2024-03-02 07:48:44 浏览: 343
您可以在 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 后,链接器在链接时会尽可能使用本地符号,而不是全局符号,从而解决符号版本不兼容的问题。
阅读全文