[英]Trouble linking against OpenCL library/ies in Cygwin with an NVIDIA GPU
我正在嘗試構建這個小型 OpenCL 項目:
https://bitbucket.org/Anteru/opencltutorial/src
在 Windows 上,在 Cygwin 中。 這是一個帶有一個 .cpp 文件和一個內核的玩具項目,用於演示 OpenCL 的使用。 所以,我下載安裝包cmake
它。 我收到錯誤消息:
CMake Error at /usr/share/cmake-3.14.5/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find OpenCL (missing: OPENCL_LIBRARY)
Call Stack (most recent call first):
/usr/share/cmake-3.14.5/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
cmake/FindOpenCL.cmake:35 (find_package_handle_standard_args)
CMakeLists.txt:6 (FIND_PACKAGE)
我對此並不CMakeCache.txt
,並繼續更改我的CMakeCache.txt
以便而不是:
OPENCL_LIBRARY:FILEPATH=OPENCL_LIBRARY-NOTFOUND
我做到了:
OPENCL_LIBRARY:FILEPATH=/cygdrive/c/Program Files/NVIDIA Corporation/OpenCL/OpenCL.dll
(這是 NVIDIA 的 OpenCL DLL 的合法路徑) 好的,現在 CMake 配置成功結束。 main.cpp
文件編譯,但鏈接失敗!:
/usr/bin/c++.exe -Wl,--enable-auto-import CMakeFiles/clTut.dir/main.cpp.o -o clTut.exe -Wl,--out-implib,libclTut.dll.a -Wl,--major-image-version,0,--minor-image-version,0 "/cygdrive/c/Program Files/NVIDIA Corporation/OpenCL/OpenCL.dll"
CMakeFiles/clTut.dir/main.cpp.o:main.cpp:(.text+0x610): undefined reference to `clGetPlatformInfo'
CMakeFiles/clTut.dir/main.cpp.o:main.cpp:(.text+0x610): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `clGetPlatformInfo'
CMakeFiles/clTut.dir/main.cpp.o:main.cpp:(.text+0x659): undefined reference to `clGetPlatformInfo'
CMakeFiles/clTut.dir/main.cpp.o:main.cpp:(.text+0x659): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `clGetPlatformInfo'
等等,幾十個這樣的錯誤。
為什么我會收到這些錯誤以及如何修復它們? 這是因為我使用的是 Cygwin 而導致 ELF/WinPE 不兼容嗎?
附加信息:
$ locate OpenCL.dll /cygdrive/c/Program Files (x86)/CodeXL/spies/OpenCL.dll /cygdrive/c/Program Files (x86)/CodeXL/spies64/OpenCL.dll /cygdrive/c/Program Files/NVIDIA Corporation/OpenCL/OpenCL.dll /cygdrive/c/Windows/LastGood/system32/OpenCL.dll /cygdrive/c/Windows/LastGood/SysWow64/OpenCL.dll /cygdrive/c/Windows/System32/OpenCL.dll /cygdrive/c/Windows/SysWOW64/OpenCL.dll
通常 Cygwin 程序類似於 Unix,並且不直接調用使用不同參數的 Windows DLL。 例如,Cygwin cygwin1.dll 提供了自己的不同於MS C 庫的C 庫,這導致共享數據的問題特別是在long 大小不同的64 位版本中。 見https://cygwin.com/cygwin-ug-net/programming.html#gcc-64
您的教程示例可以使用適當的 OpenCL 庫在 Cygwin 純環境中構建
$ cygcheck -cd | grep -i opencl
libOpenCL-devel 2.2.12-1
libOpenCL1 2.2.12-1
$ unzip Anteru-opencltutorial-cb1df4439f83.zip
Archive: Anteru-opencltutorial-cb1df4439f83.zip
inflating: Anteru-opencltutorial-cb1df4439f83/.hg_archival.txt
...
inflating: Anteru-opencltutorial-cb1df4439f83/main.cpp
inflating: Anteru-opencltutorial-cb1df4439f83/test.ppm
$ cd Anteru-opencltutorial-cb1df4439f83
/pub/tmp/Anteru-opencltutorial-cb1df4439f83
$ cmake .
-- The C compiler identification is GNU 7.4.0
-- The CXX compiler identification is GNU 7.4.0
...
-- Found OpenCL: /usr/lib/libOpenCL.dll.a
-- Configuring done
-- Generating done
-- Build files have been written to: /pub/tmp/Anteru-opencltutorial-cb1df4439f83
$ make
Scanning dependencies of target clTut
[ 50%] Building CXX object CMakeFiles/clTut.dir/main.cpp.o
/pub/tmp/Anteru-opencltutorial-cb1df4439f83/main.cpp: In function ‘int main()’:
/pub/tmp/Anteru-opencltutorial-cb1df4439f83/main.cpp:249:9: warning: ‘_cl_mem* clCreateImage2D(cl_context, cl_mem_flags, const cl_image_format*, size_t, size_t, size_t, void*, cl_int*)’ is deprecated [-Wdeprecated-declarations]
&error);
^
In file included from /pub/tmp/Anteru-opencltutorial-cb1df4439f83/main.cpp:10:0:
~~~~~~~^~~~~~
...
[100%] Linking CXX executable clTut.exe
[100%] Built target clTut
構建的程序似乎運行良好
$ ./clTut.exe
Found 1 platform(s)
(1) : Portable Computing Language
Found 1 device(s)
(1) : pthread-Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
Context created
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.