OpenCL 未定义引用,但 lib 文件位于正确位置
我在为当前需要 OpenCL 的 Projekt 设置 PC(Win 7 Ultimate 64 CPU AMD/GPU AMD)时遇到了一个奇怪的问题。
我有 MSYS,所以我正在使用 gcc 开发 mingw。我正在拼命尝试编译一个名为 openclexample 的简单作品。
注意:包含“openclexample”的目录确实包含一个 lib 文件夹,其中包括重新实现的 libOpenCL.a、OpenCL.lib 和 OVDecode64.lib。
windows/system32 中的 OpenCL.dll
现在,当我尝试使用
$ gcc -std=c99 -lOpenCL -o openclexample.exe openclexample.c
进行编译时,我得到的只是 OpenCL.def 内所有函数列表中的一堆未定义的引用错误,
Ani@ANYONE /d/StuPro/OpenCLtests
$ gcc -std=c99 -lOpenCL -o openclexample.exe openclexample.c
openclexample.c: In function 'main':
openclexample.c:214:3: warning: implicit declaration of function 'srandom' [-Wim
plicit-function-declaration]
openclexample.c:217:7: warning: implicit declaration of function 'random' [-Wimp
licit-function-declaration]
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x35): undefin
ed reference to `clGetDeviceIDs@24'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x8c): undefin
ed reference to `clCreateContext@24'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0xd9): undefin
ed reference to `clCreateCommandQueue@20'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x127): undefi
ned reference to `clCreateProgramWithSource@20'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x17f): undefi
ned reference to `clBuildProgram@24'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x1be): undefi
ned reference to `clCreateKernel@12'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x22c): undefi
ned reference to `clCreateBuffer@24'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x264): undefi
ned reference to `clCreateBuffer@24'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x29c): undefi
ned reference to `clCreateBuffer@24'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x2f1): undefi
ned reference to `clSetKernelArg@16'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x319): undefi
ned reference to `clSetKernelArg@16'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x346): undefi
ned reference to `clSetKernelArg@16'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x373): undefi
ned reference to `clSetKernelArg@16'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x3e5): undefi
ned reference to `clEnqueueWriteBuffer@36'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x433): undefi
ned reference to `clEnqueueWriteBuffer@36'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x4b2): undefi
ned reference to `clEnqueueNDRangeKernel@36'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x51f): undefi
ned reference to `clEnqueueReadBuffer@36'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x54f): undefi
ned reference to `clFinish@4'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x55d): undefi
ned reference to `clReleaseMemObject@4'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x56b): undefi
ned reference to `clReleaseMemObject@4'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x579): undefi
ned reference to `clReleaseMemObject@4'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x587): undefi
ned reference to `clReleaseKernel@4'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x595): undefi
ned reference to `clReleaseProgram@4'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x5a3): undefi
ned reference to `clReleaseCommandQueue@4'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x5b1): undefi
ned reference to `clReleaseContext@4'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x72a): undefi
ned reference to `srandom'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x75f): undefi
ned reference to `random'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x7a4): undefi
ned reference to `random'
collect2: ld returned 1 exit status
我已经阅读了数百个线程,但没有找到解决方案,有人建议将其与 -static 链接,或输入 lib 文件所在的路径...也不起作用。
如果其他人有想法,我将非常感激!
I have encountered a strange problem while setting up my PC (Win 7 Ultimate 64 CPU AMD/ GPU AMD) for our current Projekt which requires OpenCL.
I have MSYS so I am working on mingw with gcc. I am desperately trying to compile a simple piece of work called openclexample.
Note: the directory containing "openclexample" does contain a lib folder including the reimplemented libOpenCL.a, OpenCL.lib and OVDecode64.lib.
OpenCL.dll in in windows/system32
now when I try to compile using
$ gcc -std=c99 -lOpenCL -o openclexample.exe openclexample.c
all I get is a bunch of undefined reference errors in ALL funktions listet within the OpenCL.def
Ani@ANYONE /d/StuPro/OpenCLtests
$ gcc -std=c99 -lOpenCL -o openclexample.exe openclexample.c
openclexample.c: In function 'main':
openclexample.c:214:3: warning: implicit declaration of function 'srandom' [-Wim
plicit-function-declaration]
openclexample.c:217:7: warning: implicit declaration of function 'random' [-Wimp
licit-function-declaration]
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x35): undefin
ed reference to `clGetDeviceIDs@24'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x8c): undefin
ed reference to `clCreateContext@24'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0xd9): undefin
ed reference to `clCreateCommandQueue@20'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x127): undefi
ned reference to `clCreateProgramWithSource@20'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x17f): undefi
ned reference to `clBuildProgram@24'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x1be): undefi
ned reference to `clCreateKernel@12'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x22c): undefi
ned reference to `clCreateBuffer@24'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x264): undefi
ned reference to `clCreateBuffer@24'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x29c): undefi
ned reference to `clCreateBuffer@24'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x2f1): undefi
ned reference to `clSetKernelArg@16'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x319): undefi
ned reference to `clSetKernelArg@16'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x346): undefi
ned reference to `clSetKernelArg@16'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x373): undefi
ned reference to `clSetKernelArg@16'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x3e5): undefi
ned reference to `clEnqueueWriteBuffer@36'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x433): undefi
ned reference to `clEnqueueWriteBuffer@36'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x4b2): undefi
ned reference to `clEnqueueNDRangeKernel@36'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x51f): undefi
ned reference to `clEnqueueReadBuffer@36'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x54f): undefi
ned reference to `clFinish@4'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x55d): undefi
ned reference to `clReleaseMemObject@4'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x56b): undefi
ned reference to `clReleaseMemObject@4'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x579): undefi
ned reference to `clReleaseMemObject@4'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x587): undefi
ned reference to `clReleaseKernel@4'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x595): undefi
ned reference to `clReleaseProgram@4'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x5a3): undefi
ned reference to `clReleaseCommandQueue@4'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x5b1): undefi
ned reference to `clReleaseContext@4'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x72a): undefi
ned reference to `srandom'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x75f): undefi
ned reference to `random'
C:\Users\Ani\AppData\Local\Temp\ccOLx5XT.o:openclexample.c:(.text+0x7a4): undefi
ned reference to `random'
collect2: ld returned 1 exit status
I have read hundreds of threads but didn't find the solution, some suggested link it with -static, or enter the path where your lib files are... didn't work either.
I'd be really grateful if anyone else had an idea!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
链接器的参数必须按正确的顺序排列。您可以看到库搜索路径 (-L) 正常,因为链接器不会抱怨找不到库。这些符号未定义,因为 -lOpenCL 在使用它的对象/源文件之前被提及。
The arguments to the linker have to be in the right order. You can see that the library search path (-L) is OK because the linker doesn't whine about not finding libraries. The symbols are undefined because -lOpenCL was mentioned before the object/source file that is using it.