Windows 编译错误:未定义对';clGetPlatformInfo@20';
我对OpenCL编程是个新手,我想运行一个简单的程序,它在“OpenCL并行编程开发食谱”中。 事实上,我想通过以下简单的程序查询OpenCl平台:Windows 编译错误:未定义对';clGetPlatformInfo@20';,windows,qt,opencl,Windows,Qt,Opencl,我对OpenCL编程是个新手,我想运行一个简单的程序,它在“OpenCL并行编程开发食谱”中。 事实上,我想通过以下简单的程序查询OpenCl平台: #include <stdio.h> #include <stdlib.h> #include <CL/cl.h> void displayPlatformInfo(cl_platform_id id, cl_platform_info param_name,
#include <stdio.h>
#include <stdlib.h>
#include <CL/cl.h>
void displayPlatformInfo(cl_platform_id id,
cl_platform_info param_name,
const char* paramNameAsStr) {
cl_int error = 0;
size_t paramSize = 0;
error = clGetPlatformInfo( id, param_name, 0, NULL, ¶mSize );
char* moreInfo = (char*)malloc( sizeof(char) * paramSize);
error = clGetPlatformInfo( id, param_name, paramSize,moreInfo, NULL );
if (error != CL_SUCCESS ) {
perror("Unable to find any OpenCL platform information");
return;
}
printf("%s: %s\n", paramNameAsStr, moreInfo);
}
int main() {
/* OpenCL 1.2 data structures */
cl_platform_id* platforms;
/* OpenCL 1.1 scalar data types */
cl_uint numOfPlatforms;
cl_int error;
/*
Get the number of platforms
Remember that for each vendor's SDK installed on the
Computer, the number of available platform also
*/
error = clGetPlatformIDs(0, NULL, &numOfPlatforms);
if(error < 0) {
perror("Unable to find any OpenCL platforms");
exit(1);
}
// Allocate memory for the number of installed platforms.
// alloca(...) occupies some stack space but is
// automatically freed on return
platforms = (cl_platform_id*) malloc(sizeof(cl_platform_id)
* numOfPlatforms);
printf("Number of OpenCL platforms found: %d\n",
numOfPlatforms);
// We invoke the API 'clPlatformInfo' twice for each
// parameter we're trying to extract
// and we use the return value to create temporary data
// structures (on the stack) to store
// the returned information on the second invocation.
for(cl_uint i = 0; i < numOfPlatforms; ++i) {
displayPlatformInfo( platforms[i],
CL_PLATFORM_PROFILE,
"CL_PLATFORM_PROFILE" );
displayPlatformInfo( platforms[i],
CL_PLATFORM_VERSION,
"CL_PLATFORM_VERSION" );
displayPlatformInfo( platforms[i],
CL_PLATFORM_NAME,
"CL_PLATFORM_NAME" );
displayPlatformInfo( platforms[i],
CL_PLATFORM_VENDOR,
"CL_PLATFORM_VENDOR" );
displayPlatformInfo( platforms[i],
CL_PLATFORM_EXTENSIONS,
"CL_PLATFORM_EXTENSIONS" );
}
return 0;
}
因为文件路径中有空格。所以,我的问题是:为什么在我编译我的项目时,“未定义的引用clGetPlatformInfo@20”“出现了吗?还有另外两个错误(一个完全相同,另一个是“未定义引用
clGetPlatformIDs@12"")
我在网上搜索了很多天,却找不到答案(这些问题都有答案,但在Linux或Mac上……)
提前谢谢
Mathieu看起来您正在尝试构建32位应用程序,同时链接64位版本的OpenCL.lib: C:/Program Files/NVIDIA GPU计算工具包/CUDA/v6.5/lib/x64/OpenCL.lib 因此,要么以64位模式构建应用程序,要么修复指向32位版本OpenCL.lib的路径
SOURCES += \
main.cpp
QMAKE_CXXFLAGS += -std=c++0x
INCLUDEPATH += \
$$quote(C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v6.5/include)
LIBS += \
$$quote(C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v6.5/lib/x64/OpenCL.lib)