我只想尝试在Windows下使用OpenCL。
摘要 :我在尝试编译时遇到了“undefined reference to
”错误(使用命令gcc my.o -o my.exe -L "C:\Program Files (x86)\AMD APP\lib\x86_64" -l OpenCL
)。
#include <CL/cl.h>
#include <stdio.h>
int main(void) {
cl_platform_id platform;
int err;
err = clGetPlatformIDs(1, &platform, NULL);
if(err < 0) {
perror("There's No Platform!");
exit(1);
}
/* Some more code... */
system("PAUSE");
}
all: addition
addition:
gcc -c -I "C:\Program Files (x86)\AMD APP\include" my.c -o my.o
gcc my.o -o my.exe -L "C:\Program Files (x86)\AMD APP\lib\x86_64" -l OpenCL
gcc
nmake
CL.h
文件的地方)%>tree /F "C:\Program Files (x86)\AMD APP\lib\x86_64"
Auflistung der Ordnerpfade
Volumeseriennummer : D2DC-D765
C:\PROGRAM FILES (X86)\AMD APP\LIB\X86_64
libOpenCL.a
OpenCL.lib
OpenVideo64.lib
Es sind keine Unterordner vorhanden
%>tree /F "C:\Program Files (x86)\AMD APP\include"
Auflistung der Ordnerpfade
Volumeseriennummer : D2DC-D765
C:\PROGRAM FILES (X86)\AMD APP\INCLUDE
├───CAL
│ cal.h
│ calcl.h
│ cal_ext.h
│ cal_ext_counter.h
│ cal_ext_d3d10.h
│ cal_ext_d3d9.h
│
├───CL
│ cl.h
│ cl.hpp
│ cl_d3d10.h
│ cl_ext.h
│ cl_gl.h
│ cl_gl_ext.h
│ cl_platform.h
│ opencl.h
│
└───OpenVideo
OpenVideo.h
OVDecode.h
OVDecodeTypes.h
OVEncode.h
OVEncodeTypes.h
gcc addition.o -o addition.exe -L "C:\Program Files (x86)\AMD APP\lib\x86_64" -l OpenCL
addition.o:addition.c:(.text+0x2d): undefined reference to `clGetPlatformIDs@12'
addition.o:addition.c:(.text+0x83): undefined reference to `clGetDeviceIDs@24'
addition.o:addition.c:(.text+0xc2): undefined reference to `clGetDeviceIDs@24'
collect2: ld returned 1 exit status
NMAKE : fatal error U1077: "C:\prog-x86\MinGW\bin\gcc.EXE": Rückgabe-Code "0x1"
Stop.
我的问题很简单:
感谢。
更新: 删除空格之后的错误消息,如@codaddict的回答中所述。
(生成文件)
all: addition addition: gcc -c -I "C:\prog-x86\AMD-APP\include" addition.c -o addition.o gcc addition.o -o addition.exe -LC:\prog-x86\AMD-APP\lib\x86_64 -lOpenCL
(Shelldata)
%>nmake Microsoft (R) Program Maintenance Utility, Version 11.00.50727.1 Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten. gcc -c -I "C:\Program Files (x86)\AMD APP\include" addition.c -o addition.o addition.c: In function 'main': addition.c:14:9: warning: incompatible implicit declaration of built-in function 'exit' [enabled by d efault] addition.c:23:9: warning: incompatible implicit declaration of built-in function 'exit' [enabled by d efault] gcc addition.o -o addition.exe -LC:\prog-x86\AMD-APP\lib\x86_64 -lOpenCL addition.o:addition.c:(.text+0x2d): undefined reference to `clGetPlatformIDs@12' addition.o:addition.c:(.text+0x83): undefined reference to `clGetDeviceIDs@24' addition.o:addition.c:(.text+0xc2): undefined reference to `clGetDeviceIDs@24' collect2: ld returned 1 exit status NMAKE : fatal error U1077: "C:\prog-x86\MinGW\bin\gcc.EXE": Rückgabe-Code "0x1" Stop. %>
答案 0 :(得分:8)
默认的MinGW发行版仅提供用于构建x86应用程序的工具。您无法链接到OpenCL库的x64版本。因此,您必须使用MinGW-w64或使用x86版本(将库路径更改为APP SDK的x86子文件夹)。
答案 1 :(得分:1)
尝试更改
-l OpenCL
到
-lOpenCL
在编译行中。
gcc的-l
选项期望它旁边的库名称(没有lib前缀)没有任何空格。请记得在学校使用-lm
链接到libm
?
答案 2 :(得分:0)
Windows 10上的64位g ++编译器也位于bin文件夹中:
"C:\MinGW\bin\x86_64-w64-mingw32-g++.exe"
所以这对我有用:
C:\MinGW\bin>x86_64-w64-mingw32-g++ "C:\Users\...\main.cpp" -o
C:\Users\...\saxpy -L "C:\Program Files\...\x64" -lOpenCL -I
"C:\...\OpenCL\sdk\include"
注意: