我正在尝试用C ++学习OpenCL2。
我正在使用kubuntu 16.04.1 LTS和来自存储库的beignet。
我的笔记本电脑是英特尔i5-5200U没有nvidia或类似的联想。
命令clinfo
识别平台。
我在示例中找到的第一个错误是变量output2
未声明我试图对其进行评论,但仍然会收到很多链接错误...
例如http://github.khronos.org/OpenCL-CLHPP/index.html#example
这是重现链接错误的一部分的最小示例:
main.cpp中:
// Defines the target OpenCL runtime version to build the header against.
// Defaults to 200, representing OpenCL 2.0.
#define CL_HPP_TARGET_OPENCL_VERSION 200
#include <CL/cl2.hpp>
int main()
{
return 0;
}
的CMakeLists.txt:
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
set(CMAKE_CXX_STANDARD 11) # C++11...
set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required...
set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11
project(exampleopencl2)
add_executable(exampleopencl2 main.cpp)
install(TARGETS exampleopencl2 RUNTIME DESTINATION bin)
我使用KDevelop并在尝试编译此代码时获得此输出:
/home/deglans/ExampleOpenCL2/build> make -j2 mytests
Scanning dependencies of target mytests
[ 50%] Building CXX object CMakeFiles/mytests.dir/main2.cpp.o
[100%] Linking CXX executable mytests
CMakeFiles/mytests.dir/main2.cpp.o: In function `cl::detail::ReferenceHandler<_cl_device_id*>::release(_cl_device_id*)':
/usr/include/CL/cl2.hpp:1438: undefined reference to `clReleaseDevice'
CMakeFiles/mytests.dir/main2.cpp.o: In function `cl::detail::ReferenceHandler<_cl_context*>::release(_cl_context*)':
/usr/include/CL/cl2.hpp:1473: undefined reference to `clReleaseContext'
CMakeFiles/mytests.dir/main2.cpp.o: In function `cl::detail::ReferenceHandler<_cl_command_queue*>::release(_cl_command_queue*)':
/usr/include/CL/cl2.hpp:1482: undefined reference to `clReleaseCommandQueue'
collect2: error: ld returned 1 exit status
CMakeFiles/mytests.dir/build.make:94: recipe for target 'mytests' failed
make[3]: *** [mytests] Error 1
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/mytests.dir/all' failed
make[2]: *** [CMakeFiles/mytests.dir/all] Error 2
CMakeFiles/Makefile2:116: recipe for target 'CMakeFiles/mytests.dir/rule' failed
make[1]: *** [CMakeFiles/mytests.dir/rule] Error 2
Makefile:175: recipe for target 'mytests' failed
make: *** [mytests] Error 2
*** Errore: Codice di uscita 2 ***
答案 0 :(得分:0)
我通过在CMakeLists.txt文件中添加target_link_libraries(exampleopencl2 OpenCL)
解决了这个问题。