我正在尝试使用AMD OCL SDK编译一个简单的OpenCL测试程序:
#include <stdio.h>
#include <CL/cl.h>
int main() {
cl_platform_id platform;
cl_device_id device;
cl_uint num_platforms, num_devices;
cl_int err;
// Get the number of OpenCL platforms
err = clGetPlatformIDs(1, &platform, &num_platforms);
if (err != CL_SUCCESS) {
fprintf(stderr, "Error getting platform IDs: %d\n", err);
return 1;
}
printf("Number of OpenCL platforms: %u\n", num_platforms);
// Get the number of devices for the chosen platform
err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, &num_devices);
if (err != CL_SUCCESS) {
fprintf(stderr, "Error getting device IDs: %d\n", err);
return 1;
}
printf("Number of OpenCL devices: %u\n", num_devices);
printf("OpenCL is working!\n");
return 0;
}
然而,每当我试图编译它时:
g++ main.cpp -o main -I./opencl/common/inc -L./opencl/common/lib/x64 -LOpenCL
…我得到一个错误:
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\bradl\AppData\Local\Temp\cc04baXU.o:main.cpp:(.text+0x21): undefined reference to `clGetPlatformIDs'
我尝试过将OCL SDK的位置更改为项目文件夹中的位置,但没有成功。