如何使用GCC编译和链接OpenCL与Windows 7上的NVIDIA Toolkit?

时间:2013-10-27 05:52:33

标签: c windows gcc opencl

我在E:\ Program Files \ NVIDIA GPU Computing Toolkit \ CUDA \ v4.2 \上安装了NVIDIA GPU计算工具包,我试图编译opencl示例程序:

gcc hello.c -I "E:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\include" -L "E:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\lib\Win32" -lOpenCL -o hello.exe

我有链接器错误:

E:\Users\Lammar\AppData\Local\Temp/cc0Kbaaa.o(.text+0x142):hello.c: undefined re
ference to `clGetPlatformIDs@12'
E:\Users\Lammar\AppData\Local\Temp/cc0Kbaaa.o(.text+0x179):hello.c: undefined re
ference to `clGetDeviceIDs@24'
E:\Users\Lammar\AppData\Local\Temp/cc0Kbaaa.o(.text+0x1b1):hello.c: undefined re
ference to `clCreateContext@24'
E:\Users\Lammar\AppData\Local\Temp/cc0Kbaaa.o(.text+0x1e0):hello.c: undefined re
ference to `clCreateCommandQueue@20'
E:\Users\Lammar\AppData\Local\Temp/cc0Kbaaa.o(.text+0x218):hello.c: undefined re
ference to `clCreateBuffer@24'
E:\Users\Lammar\AppData\Local\Temp/cc0Kbaaa.o(.text+0x24c):hello.c: undefined re
ference to `clCreateProgramWithSource@20'
E:\Users\Lammar\AppData\Local\Temp/cc0Kbaaa.o(.text+0x284):hello.c: undefined re
ference to `clBuildProgram@24'
E:\Users\Lammar\AppData\Local\Temp/cc0Kbaaa.o(.text+0x2a4):hello.c: undefined re
ference to `clCreateKernel@12'
E:\Users\Lammar\AppData\Local\Temp/cc0Kbaaa.o(.text+0x2cc):hello.c: undefined re
ference to `clSetKernelArg@16'
E:\Users\Lammar\AppData\Local\Temp/cc0Kbaaa.o(.text+0x2fc):hello.c: undefined re
ference to `clEnqueueTask@20'
E:\Users\Lammar\AppData\Local\Temp/cc0Kbaaa.o(.text+0x34e):hello.c: undefined re
ference to `clEnqueueReadBuffer@36'
E:\Users\Lammar\AppData\Local\Temp/cc0Kbaaa.o(.text+0x36d):hello.c: undefined re
ference to `clFlush@4'
E:\Users\Lammar\AppData\Local\Temp/cc0Kbaaa.o(.text+0x37e):hello.c: undefined re
ference to `clFinish@4'
E:\Users\Lammar\AppData\Local\Temp/cc0Kbaaa.o(.text+0x38f):hello.c: undefined re
ference to `clReleaseKernel@4'
E:\Users\Lammar\AppData\Local\Temp/cc0Kbaaa.o(.text+0x3a0):hello.c: undefined re
ference to `clReleaseProgram@4'
E:\Users\Lammar\AppData\Local\Temp/cc0Kbaaa.o(.text+0x3b1):hello.c: undefined re
ference to `clReleaseMemObject@4'
E:\Users\Lammar\AppData\Local\Temp/cc0Kbaaa.o(.text+0x3c2):hello.c: undefined re
ference to `clReleaseCommandQueue@4'
E:\Users\Lammar\AppData\Local\Temp/cc0Kbaaa.o(.text+0x3d3):hello.c: undefined re
ference to `clReleaseContext@4'
collect2: ld returned 1 exit status

它有什么问题吗?如何让它发挥作用?

1 个答案:

答案 0 :(得分:1)

在阅读了一些相关问题后,我安装了mingw-utils,然后在http://pastebin.com/f2ac38b2f上使用dlltool -l libOpenCL.a -d OpenCL.def -A -k并使用:gcc hello.c -I "E:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\include" -lOpenCL -o hello.exe进行编译。现在它编译并正常工作。