我是 OpenCL 新手,并尝试在 ubuntu 12.04 上运行来自 nvidia“OpenCL 设备查询”的示例代码(https://developer.nvidia.com/opencl)
我得到了很多未定义的引用:
std::basic_string
shrLogEx
shrLog
shrSetLogFileName
我想我在包含正确的头文件时犯了一些错误,但无法找到问题所在。谁能告诉我如何运行示例代码吗?
以下是错误消息:
oclDeviceQuery.o: In function `main':
oclDeviceQuery.cpp:(.text+0x45): undefined reference to `shrSetLogFileName'
oclDeviceQuery.cpp:(.text+0x61): undefined reference to `shrLog'
oclDeviceQuery.cpp:(.text+0x77): undefined reference to `std::allocator<char>::allocator()'
oclDeviceQuery.cpp:(.text+0x92): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
oclDeviceQuery.cpp:(.text+0xa1): undefined reference to `std::allocator<char>::~allocator()'
oclDeviceQuery.cpp:(.text+0xb0): undefined reference to `shrLog'
oclDeviceQuery.cpp:(.text+0xca): undefined reference to `oclGetPlatformID'
oclDeviceQuery.cpp:(.text+0x144): undefined reference to `shrLog'
oclDeviceQuery.cpp:(.text+0x15d): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator+=(char const*)'
oclDeviceQuery.cpp:(.text+0x176): undefined reference to `shrLog'
oclDeviceQuery.cpp:(.text+0x191): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator+=(char const*)'
oclDeviceQuery.cpp:(.text+0x1e3): undefined reference to `shrLog'
oclDeviceQuery.cpp:(.text+0x1fc): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator+=(char const*)'
oclDeviceQuery.cpp:(.text+0x215): undefined reference to `shrLog'
oclDeviceQuery.cpp:(.text+0x230): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator+=(char const*)'
oclDeviceQuery.cpp:(.text+0x244): undefined reference to `shrLog'
oclDeviceQuery.cpp:(.text+0x258): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator+=(char const*)'
oclDeviceQuery.cpp:(.text+0x26c): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator+=(char const*)'
oclDeviceQuery.cpp:(.text+0x27b): undefined reference to `shrLog'
oclDeviceQuery.cpp:(.text+0x2ca): undefined reference to `shrLog'
oclDeviceQuery.cpp:(.text+0x2e5): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator+=(char const*)'
oclDeviceQuery.cpp:(.text+0x30b): undefined reference to `shrLog'
oclDeviceQuery.cpp:(.text+0x32e): undefined reference to `shrLog'
oclDeviceQuery.cpp:(.text+0x366): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator+=(char const*)'
oclDeviceQuery.cpp:(.text+0x39f): undefined reference to `shrLog'
oclDeviceQuery.cpp:(.text+0x43b): undefined reference to `shrLog'
oclDeviceQuery.cpp:(.text+0x465): undefined reference to `shrLog'
oclDeviceQuery.cpp:(.text+0x4b4): undefined reference to `shrLog'
oclDeviceQuery.cpp:(.text+0x4c3): undefined reference to `shrLog'
oclDeviceQuery.cpp:(.text+0x4e4): undefined reference to `oclPrintDevInfo'
oclDeviceQuery.cpp:(.text+0x4f8): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator+=(char const*)'
oclDeviceQuery.cpp:(.text+0x511): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator+=(char const*)'
oclDeviceQuery.cpp:(.text+0x548): undefined reference to `shrLog'
oclDeviceQuery.cpp:(.text+0x563): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator+=(char const*)'
oclDeviceQuery.cpp:(.text+0x572): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::c_str() const'
oclDeviceQuery.cpp:(.text+0x589): undefined reference to `shrLogEx'
oclDeviceQuery.cpp:(.text+0x598): undefined reference to `shrLog'
oclDeviceQuery.cpp:(.text+0x5d2): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
oclDeviceQuery.cpp:(.text+0x5fa): undefined reference to `std::allocator<char>::~allocator()'
oclDeviceQuery.cpp:(.text+0x617): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
oclDeviceQuery.o: In function `__static_initialization_and_destruction_0(int, int)':
oclDeviceQuery.cpp:(.text+0x658): undefined reference to `std::ios_base::Init::Init()'
oclDeviceQuery.cpp:(.text+0x65d): undefined reference to `std::ios_base::Init::~Init()'
oclDeviceQuery.o: In function `__oclCheckErrorEX(int, int, void (*)(int), char const*, int)':
oclDeviceQuery.cpp:(.text._Z17__oclCheckErrorEXiiPFviEPKci[__oclCheckErrorEX(int, int, void (*)(int), char const*, int)]+0x3b): undefined reference to `oclErrorString'
oclDeviceQuery.cpp:(.text._Z17__oclCheckErrorEXiiPFviEPKci[__oclCheckErrorEX(int, int, void (*)(int), char const*, int)]+0x5c): undefined reference to `shrLog'
oclDeviceQuery.cpp:(.text._Z17__oclCheckErrorEXiiPFviEPKci[__oclCheckErrorEX(int, int, void (*)(int), char const*, int)]+0x89): undefined reference to `shrLogEx'
oclDeviceQuery.o:(.eh_frame+0xe7): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
最佳答案
这个问题实际上不是你的错,而是 NVIDIA 的错:本质上他们已经放弃了 opencl 支持。这并不奇怪,因为他们希望你使用 CUDA。他们从主要的 cuda SDK 中取出了 opencl 示例,而是将它们一一上传。现在他们缺少依赖项并且都不起作用。
要解决此问题,请下载旧版本的 SDK:从 https://developer.nvidia.com/cuda-toolkit-42-archive 选择适当的版本
对于 Linux:下载后,使用通常的 ./gpucomputing*.run
从终端运行它。在安装过程中,我建议当提示您选择将sdk放在您的主文件夹/home/usrname/gpusdk
中,否则它将解压到root。接下来我收到一条关于找不到 CUDA 的消息,所以我将其留空。
在终端中,导航至 /home/usrname/gpusdk/OpenCL
并输入 make
。这次它将构建所需的库,为您排序链接,并且应该可以很好地编译所有示例(至少对我来说是这样)
关于OpenCL 设备查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20105039/