无法编译项目“ /usr/local/lib/libOpenCL.so.1:添加符号时出错:命令行缺少DSO”

时间:2018-08-19 22:07:39

标签: cmake

我已经审查了所有可能的答案,并在尝试解决此问题时尝试了不同的方法,但是似乎没有解决方案。

我正在尝试编译使用OpenCL的项目,在将OpenCL添加到CMake(我有Ubuntu Linux)之前,编译还不错,并且出现以下错误。

/usr/bin/ld: CMakeFiles/client_opencl.dir/simpleCL.cpp.o: undefined reference to symbol 'clEnqueueNDRangeKernel@@OPENC│/usr/bin/ld: CMakeFiles/client_opencl.dir/simpleCL.cpp.o: undefined reference to symbol 'clEnqueueNDRangeKernel@@OPENCL
L_1.0'                                                                                                                │_1.0'
/usr/local/lib/libOpenCL.so.1: error adding symbols: DSO missing from command line

我确认目标文件(/usr/local/lib/libOpenCL.so.1)到位,并且包含请求的符号。我通过命令> readelf -s libOpenCL.so | grep "clEnqueueNDRangeKernel"执行此操作。这就是我得到的:

/usr/local/lib$ readelf -s libOpenCL.so.1 | grep "clEnqueueNDRangeKernel"
    37: 0000000000012580   388 FUNC    GLOBAL DEFAULT   12 clEnqueueNDRangeKernel@@OPENCL_1.0

我有以下CMakeList.txt:

cmake_minimum_required(VERSION 3.0)

project(ArrayFire-Example-Benchmarks VERSION 3.5.0 LANGUAGES CXX)

include(CheckCXXCompilerFlag)

FIND_PACKAGE( Boost 1.58 COMPONENTS program_options REQUIRED COMPONENTS date_time filesystem thread system)
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )


CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)

if(COMPILER_SUPPORTS_CXX14)
    if (APPLE)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -framework OpenCL -std=c++14")
    elseif(LINUX)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -pthread")
    else()
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
    endif()
elseif(COMPILER_SUPPORTS_CXX11)
    if (APPLE)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -framework OpenCL -std=c++11")
    elseif(LINUX)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread")
    else()
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
    endif()
elseif(COMPILER_SUPPORTS_CXX0X)
    if (APPLE)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -framework OpenCL -std=c++0x")
    elseif(LINUX)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -pthread")
    else()
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
    endif()
else()
    message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()

file(COPY kernel.c DESTINATION ${CMAKE_BINARY_DIR})

find_package(ArrayFire)
find_package(OpenCL REQUIRED)

include_directories(${OpenCL_INCLUDE_DIRS})
link_directories(${OpenCL_LIBRARY})

## load in pkg-config support
find_package(PkgConfig)

## use pkg-config to get hints for 0mq locations
pkg_check_modules(PC_ZeroMQ QUIET zmq)

## use the hint from above to find where 'zmq.hpp' is located
find_path(
        ZeroMQ_INCLUDE_DIR
        NAMES zmq.hpp
        PATHS ${PC_ZeroMQ_INCLUDE_DIRS}
)

## use the hint from about to find the location of libzmq
find_library(
        ZeroMQ_LIBRARY
        NAMES zmq
        PATHS ${PC_ZeroMQ_LIBRARY_DIRS}
)

if(ArrayFire_OpenCL_FOUND)
    if (APPLE)
        add_executable(kernel_test kernel_test.cpp common.h xor128.h simpleCL.cpp simpleCL.h)
        target_link_libraries(kernel_test ArrayFire::afopencl ${ZeroMQ_LIBRARY} libstockfish.a ${Boost_LIBRARIES} Boost::filesystem)

        add_executable(server_opencl server.cpp common.h xor128.h simpleCL.cpp simpleCL.h)
        target_link_libraries(server_opencl ArrayFire::afopencl ${ZeroMQ_LIBRARY} libstockfish.a ${Boost_LIBRARIES} Boost::filesystem)

        ## add the include directory to our compile directives
        target_include_directories(server_opencl PUBLIC ${ZeroMQ_INCLUDE_DIR})

        add_executable(client_opencl client.cpp common.h xor128.h simpleCL.cpp simpleCL.h)
        target_link_libraries(client_opencl ArrayFire::afopencl ${ZeroMQ_LIBRARY} libstockfish.a ${Boost_LIBRARIES} Boost::filesystem )

        ## add the include directory to our compile directives
        target_include_directories(client_opencl PUBLIC ${ZeroMQ_INCLUDE_DIR})
    elseif(LINUX)
        add_executable(server_opencl server.cpp common.h xor128.h simpleCL.cpp simpleCL.h)
        target_link_libraries(server_opencl ArrayFire::afopencl ${ZeroMQ_LIBRARY} ${CMAKE_SOURCE_DIR}/libstockfish.so ${Boost_LIBRARIES} Boost::filesystem)

        ## add the include directory to our compile directives
        target_include_directories(server_opencl PUBLIC ${ZeroMQ_INCLUDE_DIR})

        add_executable(client_opencl client.cpp common.h xor128.h simpleCL.cpp simpleCL.h)
        target_link_libraries(client_opencl ArrayFire::afopencl ${ZeroMQ_LIBRARY} ${CMAKE_SOURCE_DIR}/libstockfish.so ${Boost_LIBRARIES} Boost::filesystem)

        ## add the include directory to our compile directives
        target_include_directories(client_opencl PUBLIC ${ZeroMQ_INCLUDE_DIR})
    endif()
endif()

有什么想法可能会发生这种情况?我已经尝试在target_link_libraries中切换OPENCL库的顺序和源顺序,没有任何帮助...

提前谢谢!

0 个答案:

没有答案