GCC:编译Windows上的OpenCL的主机 [英] GCC: Compiling an OpenCL host on Windows
问题描述
我只是想尝试一下在Windows下使用OpenCL的。
摘要的:我得到了一个未定义的引用
错误当我试图编译(使用命令的gcc -o my.o -L my.exeC:\\ Program Files文件(x86)的\\ AMD APP \\ lib目录\\ x86_64的-l的OpenCL
)。
我的code
的#include< CL / cl.h>
#包括LT&;&stdio.h中GT;诠释主要(无效){
cl_platform_id平台;
INT犯错; ERR = clGetPlatformIDs(1,与平台,NULL);
如果(ERR℃,){
PERROR(没有平台!);
出口(1);
} / *一些较code ... * / 系统(暂停);
}
的Makefile
所有:除加成:
GCC -c -IC:\\ Program Files文件(x86)的\\ AMD APP \\包括my.c -o my.o
GCC my.o -o my.exe -LC:\\ Program Files文件(x86)的\\ AMD APP \\ lib目录\\ x86_64的-l的OpenCL
使用的程序
- 的MinGW的
GCC
- Visual Studio中的
NMAKE
- AMD的的OpenCL™SDK APP (这就是我把OpenCL的库,并从
CL.h
文件)
APP SDK的文件夹的结构
%GT;树/ FC:\\ 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.libES信德keine Unterordner vorhanden
%GT;树/ FC:\\ Program Files文件(x86)的\\ AMD APP \\包括
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
OVDe code.h
OVDe codeTypes.h
烤箱code.h
烤箱codeTypes.h
错误信息
的gcc -o addition.o -L addition.exeC:\\ Program Files文件(x86)的\\ AMD APP \\ lib目录\\ x86_64的-l的OpenCL
addition.o:addition.c :(文字+ 0x2d):未定义的引用`clGetPlatformIDs @ 12'
addition.o:addition.c :(文字+ 0X83):未定义的引用`clGetDeviceIDs @ 24'
addition.o:addition.c :(文字+为0xC2):未定义的引用`clGetDeviceIDs @ 24'
collect2:劳工处返回1退出状态
NMAKE:致命错误U1077:C:\\前卫的x86 \\ MinGW的\\ BIN \\ gcc.EXE:Rückgabe-code为0x1
停止。
我的问题
我的问题很简单:
- 为什么我的code编译预期如何?
- 我能做些什么来摆脱这个问题的?
感谢。
更新:的后,错误信息的下探空间像@codaddict的回答说明
的(Makefile文件)的
所有:除加成:
GCC -c -IC:\\前卫的x86 \\ AMD-APP \\包括addition.c -o addition.o
GCC addition.o -o addition.exe -LC:\\前卫的x86 \\ AMD-APP \\ lib目录\\ x86_64的-lOpenCL的(Shelldata)的
%GT; NMAKE微软(R)程序维护工具,版本11.00.50727.1
版权所有(C)微软公司。 ALLE Rechte vorbehalten。 GCC -c -IC:\\ Program Files文件(x86)的\\ AMD APP \\包括addition.c -o addition.o
addition.c:在函数'主':
[用d启用内置函数退出不兼容的隐式声明:addition.c:14:9:警告
EFAULT]
[用d启用内置函数退出不兼容的隐式声明:addition.c:23:9:警告
EFAULT]
GCC addition.o -o addition.exe -LC:\\前卫的x86 \\ AMD-APP \\ lib目录\\ x86_64的-lOpenCL
addition.o:addition.c :(文字+ 0x2d):未定义的引用`clGetPlatformIDs @ 12'
addition.o:addition.c :(文字+ 0X83):未定义的引用`clGetDeviceIDs @ 24'
addition.o:addition.c :(文字+为0xC2):未定义的引用`clGetDeviceIDs @ 24'
collect2:劳工处返回1退出状态
NMAKE:致命错误U1077:C:\\前卫的x86 \\ MinGW的\\ BIN \\ gcc.EXE:Rückgabe-code为0x1
停止。%GT;
块引用>解决方案默认MinGW的分布只船的工具构建x86应用。您无法链接对OpenCL的库x64版本。所以,你要么必须使用的MinGW-W64 或使用x86版(改库路径APP SDK的子文件夹的x86)。
I just wanted to try out using OpenCL under Windows.
Abstract: I got an "
undefined reference to
" error when I tried to compile (using the commandgcc my.o -o my.exe -L "C:\Program Files (x86)\AMD APP\lib\x86_64" -l OpenCL
).
My Code
#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"); }
Makefile
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
Used Programs
- MinGW's
gcc
- Visual Studio's
nmake
- AMD's OpenCL™ APP SDK (that's where I took the OpenCL library and the
CL.h
file from)The Structure of APP SDK's Folders
%>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
Error Message
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.
My Questions
My questions are simple:
- Why doesn't my code compile how it is expected to?
- What can I do to get rid of this problem?
Thanks.
UPDATE: The error message after dropping the spaces like described in @codaddict 's answer.
(Makefile)
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. %>
解决方案The default MinGW distribution only ships tools for building x86 applications. You cannot link against the x64 version of the OpenCL library. So you either have to use MinGW-w64 or use the x86 version (change the library path to the x86 subfolder of the APP SDK).
这篇关于GCC:编译Windows上的OpenCL的主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!