在Mingw Nvidia SDK上编译OpenCL [英] Compile OpenCL on Mingw Nvidia SDK

查看:112
本文介绍了在Mingw Nvidia SDK上编译OpenCL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用Mingw和Nvidia SDK编译OpenCL?

Is it possible to compile OpenCL using Mingw and Nvidia SDK?

我知道它没有得到官方的支持,但这没有任何意义.这些库不是作为静态链接库提供的吗?我的意思是,一旦使用可能的编译器进行编译并成功链接,那应该是什么问题?

I'm aware that its not officially supported but that just doesn't make sense. Aren't the libraries provided as a statically linked libraries? I mean once compiled with whatever compiler that may be, and linked successfully, whats should be the problem?

我设法编译并成功将我的代码链接到Nvidia SDK随附的OpenCL库,但是该可执行文件在clGetPlatformIDs处抛出了Segmentation Fault,这是我代码中的第一个OpenCL调用.

I managed to compile and successfully link my code to OpenCL libraries provided with Nvidia's SDK, however the executable throws Segmentation Fault at clGetPlatformIDs which is the first OpenCL call in my code.

这是我的编译命令

x86_64-w64-mingw32-g++ -std=c++11 File.cpp \
-L"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\lib\x64" \
-I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\include" \
-gcoff -lOpenCL -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 \
-lshell32 -lole32 -loleaut32 \
-luuid -lodbc32 -lodbccp32 -luser32 -lgdi32 -lmingwex -m64 \
-DWIN32 -D_DEBUG -D_CONSOLE

请注意,这些库来自示例OpenCL代码的.sln文件.

Note that these libraries were taken from the .sln file of the sample OpenCL code.

我尝试了这些库的各种组合,但似乎无济于事.

I tried various combinations of these libraries and nothing seems to work.

还有没有一种方法可以使用Mingw进行编译,并使用其他方法进行链接?我不确定还有什么可能.

Also is there a way to compile using Mingw and link using something else? I'm not sure what the something else might be.

推荐答案

我们已经能够通过使用MinGW reimp和dlltool实用程序为"OpenCL.dll" DLL创建导入库"libOpenCL.a"来做到这一点. .这是我们遵循的步骤:

We have been able to do this by using the MinGW reimp and dlltool utilities to create an import library "libOpenCL.a" for the "OpenCL.dll" DLL. Here are the steps we followed:

  • 步骤1:确保已安装mingw-utils(用于reimp和dlltool).如果没有,请在MinGW提示符下键入:

  • step 1: Make sure you have mingw-utils installed (for reimp and dlltool). If you don't, at a MinGW prompt, type:

mingw-get install mingw-utils

mingw-get install mingw-utils

步骤2:接下来,键入以下命令:

step 2: Next, type the following command:

reimp OpenCL.lib

reimp OpenCL.lib

这将产生一个OpenCL.def和libOpenCL.a文件.如果结果是导入库无效或损坏",则应该执行第二步.

This should yield an OpenCL.def and libOpenCL.a file. If the result is something along the lines of "invalid or corrupt import library", the alternative step 2 should work.

dlltool -l libOpenCL.a -d OpenCL.def -A -k

dlltool -l libOpenCL.a -d OpenCL.def -A -k

您现在可以链接到新创建的libOpenCL.a.如果仍然看到丢失的符号,请将其添加到.def文件中,然后重复dlltool命令.

You can now link against the newly created libOpenCL.a. If you still see missing symbols, add them to the .def file and repeat the dlltool command.

由于以下帖子中提供的信息可供参考,因此我们能够使所有这些工作正常进行:

We were able to get this all working thanks to the information found in following posts, for reference:

  1. http://oscarbg.blogspot.com/2009/12/opencl-with-mingw.html
  2. http://www.mingw.org/wiki/CreateImportLibraries (我只能粘贴2个链接)
  1. http://oscarbg.blogspot.com/2009/12/opencl-with-mingw.html
  2. http://www.mingw.org/wiki/CreateImportLibraries (I can only paste 2 links)

这篇关于在Mingw Nvidia SDK上编译OpenCL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆