1

我正在尝试运行一个代码,它使用来自 boost 计算库和 arrayfire 库的函数。尝试构建代码时出现以下错误:

Scanning dependencies of target hello
[ 50%] Building CXX object CMakeFiles/hello.dir/hello.cpp.o
In file included from /opt/arrayfire/include/CL/cl.h:32,
                 from /usr/include/boost/compute/cl.hpp:19,
                 from /usr/include/boost/compute/system.hpp:20,
                 from /usr/include/boost/compute/algorithm/accumulate.hpp:17,
                 from /usr/include/boost/compute/algorithm.hpp:18,
                 from /usr/include/boost/compute.hpp:14,
                 from /home/rcms/debruijn/arrayfire/hello.cpp:2:
/opt/arrayfire/include/CL/cl_version.h:34:104: note: #pragma message: cl_version.h: CL_TARGET_OPENCL_VERSION is not defined. Defaulting to 220 (OpenCL 2.2)
   34 | #pragma message("cl_version.h: CL_TARGET_OPENCL_VERSION is not defined. Defaulting to 220 (OpenCL 2.2)")
      |                                                                                                        ^
[100%] Linking CXX executable hello
/usr/bin/ld: CMakeFiles/hello.dir/hello.cpp.o: undefined reference to symbol 'clGetDeviceIDs@@OPENCL_1.0'
/usr/bin/ld: /opt/arrayfire/lib64/libOpenCL.so.1: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/hello.dir/build.make:85: hello] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/hello.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

我正在使用的代码是一个非常简单的 helloworld,它使用了两个库中的函数。

#include <iostream>
#include <boost/compute.hpp>
#include <arrayfire.h>
namespace compute = boost::compute;
using namespace af;
int main()
{
     // Boost Compute Part
    // get the default device
    compute::device device = compute::system::default_device();
    // print the device's name and platform
    std::cout << "hello from " << device.name();
    std::cout << " (platform: " << device.platform().name() << ")" << std::endl;
    // Array Fire Part
    std::cout<< "ArrayFire Part:" << std::endl;
    af::setDevice(0);
    af::info();
    return 0;
}

用于构建项目的 CMakeList 是:

cmake_minimum_required(VERSION 3.0)
project(deBruijn_Graph)
find_package(ArrayFire)
add_executable(hello hello.cpp)
target_link_libraries(hello ArrayFire::afopencl)

我没有编程背景。请指导我做错了什么。如何在一个代码中将这两个库链接在一起?

问候,哈桑

4

0 回答 0