![为什么安装 fglrx 驱动程序和 amd app sdk 后 OpenCL 无法与 gcc 链接?](https://linux22.com/image/51370/%E4%B8%BA%E4%BB%80%E4%B9%88%E5%AE%89%E8%A3%85%20fglrx%20%E9%A9%B1%E5%8A%A8%E7%A8%8B%E5%BA%8F%E5%92%8C%20amd%20app%20sdk%20%E5%90%8E%20OpenCL%20%E6%97%A0%E6%B3%95%E4%B8%8E%20gcc%20%E9%93%BE%E6%8E%A5%EF%BC%9F.png)
我已按照本教程在我的计算机上安装了 fglrx 驱动程序:http://wiki.cchtml.com/index.php/Fedora_18_Installation_Guide,安装了 opencl-headers 包,最后安装了 amd app sdk 当我运行时
gcc -lOpenCL someprogram.c
我得到了错误
/usr/bin/ld: cannot find -lOpenCL
collect2: error: ld returned 1 exit status
我从 fglrxinfo 得到以下信息
display: :0 screen: 0
OpenGL vendor string: Advanced Micro Devices, Inc.
OpenGL renderer string: AMD Radeon HD 6310 Graphics
OpenGL version string: 4.2.12422 Compatibility Profile Context 13.152
并且/usr/lib64/中没有libopencl.so
我想出了如何通过运行来链接它
gcc -I/opt/AMDAPP/include -L/opt/AMDAPP/lib/x86_64 -lOpenCL hellocl.c -o hello
答案1
您需要实际的库才能ld
链接。仅编译需要标头,链接不需要。它将寻找libOpenCL.so
在您的库路径中调用的文件。从ld
联机帮助页:
-l namespec
--library=namespec
Add the archive or object file specified by namespec to the list of
files to link. This option may be used any number of times. If
namespec is of the form :filename, ld will search the library path
for a file called filename, otherwise it will search the library path
for a file called libnamespec.a.
On systems which support shared libraries, ld may also search for
files other than libnamespec.a. Specifically, on ELF and SunOS
systems, ld will search a directory for a library called
libnamespec.so before searching for one called libnamespec.a.
(By convention, a ".so" extension indicates a shared library.)
Note that this behavior does not apply to :filename, which always
specifies a file called
filename.
尝试将库符号链接到构建系统正在寻找的名称。
ln -s /usr/lib64/libopencl.so /usr/lib64/libOpenCL.so