GCC: Compiling an OpenCL host on Windows
来源:互联网 发布:linux telnet ip 端口 编辑:程序博客网 时间:2024/06/06 00:53
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 command gcc 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: additionaddition: 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 OrdnerpfadeVolumeseriennummer : D2DC-D765C:\PROGRAM FILES (X86)\AMD APP\LIB\X86_64 libOpenCL.a OpenCL.lib OpenVideo64.libEs sind keine Unterordner vorhanden%>tree /F "C:\Program Files (x86)\AMD APP\include"Auflistung der OrdnerpfadeVolumeseriennummer : D2DC-D765C:\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 OpenCLaddition.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 statusNMAKE : 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: additionaddition: 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)
%>nmakeMicrosoft (R) Program Maintenance Utility, Version 11.00.50727.1Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten. gcc -c -I "C:\Program Files (x86)\AMD APP\include" addition.c -o addition.oaddition.c: In function 'main':addition.c:14:9: warning: incompatible implicit declaration of built-in function 'exit' [enabled by default]addition.c:23:9: warning: incompatible implicit declaration of built-in function 'exit' [enabled by default] gcc addition.o -o addition.exe -LC:\prog-x86\AMD-APP\lib\x86_64 -lOpenCLaddition.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 statusNMAKE : fatal error U1077: "C:\prog-x86\MinGW\bin\gcc.EXE": Rückgabe-Code "0x1"Stop.%>
2 Answers
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).
Try changing
-l OpenCL
to
-lOpenCL
in the compile line.
The -l
option of gcc expects the name of the library (without the lib prefix) right next to it without any space. Remember using -lm
in school to link to libm
?
-L
? – codaddict Sep 15 '12 at 14:47- GCC: Compiling an OpenCL host on Windows
- Compiling GCC on OS X
- Compiling C extension modules on Windows
- Compiling Wireshark using MS VS Express 2012 on Windows 7
- gcc compiling for debugging
- Compiling Erlang on Ubuntu
- Compiling Erlang on Ubuntu
- Compiling OpenSSL on Linux
- An Introduction to OpenCL
- Windows 下编译 VXL 的注意事项(Notes for compiling VXL on Windows)
- Errors when compiling cross gcc
- Compiling Cairo for Windows
- Compiling Graphite under Windows
- TOUCHLIB COMPILING INSTRUCTIONS (WINDOWS)
- OpenCL: Windows下使用OpenCL
- OpenCL: Windows下使用OpenCL
- How to extend an LVM disk on a RHEL guest machine running on VMware host?
- My GCC Environment on Windows Vista
- linux中sudo命令的使用方法
- COPRA-for-AutoCAD 2005
- HTML5解决跨域问题
- IOS添加通讯录
- TabHost、TabWidgt、Tabcontent之间的关系
- GCC: Compiling an OpenCL host on Windows
- 数组、随机数、时间、字符串在购物系统中的应用
- C语言实现全排列
- Eclipse安装ADT和介绍DDMS
- C#创建线程三种方式
- Telelogic.Rhapsody.v7.4.Windows-ISO 1CD(嵌入式仿真开发)
- 软件测试
- CoreData
- 无题
gcc addition.o -o addition.exe "C:\Program Files (x86)\AMD APP\lib\x86_64\OpenCL.lib" -l OpenCL
? – fridojet Sep 15 '12 at 15:24