C++ 使用NVIDIA GPU与Cygwin中的OpenCL库/ies链接时出现问题

C++ 使用NVIDIA GPU与Cygwin中的OpenCL库/ies链接时出现问题,c++,cygwin,opencl,linker-errors,C++,Cygwin,Opencl,Linker Errors,我正在尝试构建这个小型OpenCL项目: 在Windows上,在Cygwin中。这是一个玩具项目,有一个.cpp文件和一个内核来演示OpenCL的使用。因此,我下载了这个软件包并cmakeit。我收到错误消息: CMake Error at /usr/share/cmake-3.14.5/Modules/FindPackageHandleStandardArgs.cmake:137 (message): Could NOT find OpenCL (missing: OPENCL_LIBR

我正在尝试构建这个小型OpenCL项目:

在Windows上,在Cygwin中。这是一个玩具项目,有一个.cpp文件和一个内核来演示OpenCL的使用。因此,我下载了这个软件包并
cmake
it。我收到错误消息:

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)
我对此毫不犹豫,继续更改我的
cmakcache.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不兼容吗

其他信息:

  • 我的机器既有集成的英特尔图形(630-咖啡湖),又有一个Quadro P1000
  • 我已经将CUDA10.2和AMDCodexl安装到了它们的默认位置(不管为什么)
  • 查找OpenCL DLL文件时,我发现:
    $ 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,而Windows DLL使用 另一种模式。 例如,Cygwin cygwin1.dll提供了与 MS C库,这会导致数据共享问题,特别是在64位版本中,long的大小不同。看见

您的教程示例可以在Cygwin纯环境中使用适当的OpenCL库构建

 $ 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

使用Cygwin构建,您应该使用它附带的opencl。您是否安装了
libOpenCL-devel
软件包?有关该软件包的信息,请参阅@matzeri:Cygwin没有绑定与NVIDIA兼容的OpenCL驱动程序-据我所知。不要使用Cygwin编译器和工具。或者使用NVidia库,或者在Cygwin上构建。两者都不能起作用。@matzeri:你能把这变成一个答案吗?我会的。但是,如果需要使用Nvidia库编译,一个解决方案是使用明文库OpenCL库不支持英伟达GPU,AFAICT。在问题中澄清了这一点。当然不是,正如我所写的,这是一个纯粹的Cygwin环境。要链接到英伟达,需要使用不同的环境,例如明文,如