无法将 Windows 上的 OpenCL 与 GHC 链接
我正在尝试将 OpenCLRaw 绑定提升到可以在 Windows 上使用它们的程度。我已经在 github 上分叉了 OpenCLRaw 存储库,以便我可以根据需要进行修改。我的分行在这里: https://github.com/dagit/OpenCLRaw
我大部分时间都在我的“FunPtr”分支上工作。
我遇到的问题是这样的:我安装了 AMD 的 OpenCL SDK,将其 Visual Studio 特定的 .lib 文件转换为 gcc 可以处理的文件(.a 文件),但 ghc 似乎无法与其链接。我在 OpenCL API 中使用的所有内容都得到了未定义的符号。
我能够构建一个“简单的”C 程序,并使用我生成的 .a 文件和来自 mingw(而不是来自 Haskell 安装)的 gcc 链接它。我正在使用 Haskell 平台的最新 Windows 版本。
这些是我用于生成 .a 文件的步骤: http://forums.amd.com/forum/messageview.cfm?catid=390& threadid=138890
我使用了示例脚本中的命令(例如 gendef 和 dlltool)。我尝试尽可能多地使用 32 位,因为我知道 GHC 希望所有内容都是 32 位,所以我不认为这是 32 位与 64 位的问题。
有谁知道在 ghc 下调用 gcc 与我从 mingw 获得的 gcc 是否有不同?
我还使用了 ghc 命令行(我使用 cabal-dev --verbose=3 来检查命令行),但我仍然无法将其调整为工作状态。
任何帮助将不胜感激!
I'm trying to get the OpenCLRaw bindings to a point where I can use them on windows. I've forked the the OpenCLRaw repo on github so I can make modifications as needed. My branch is here:
https://github.com/dagit/OpenCLRaw
I've been mostly working out of my "FunPtr" branch.
The issue I'm having is this: I installed AMD's OpenCL SDK, converted their Visual Studio specific .lib file to a file that gcc can handle (.a file), but ghc can't seem to link with it. I get undefined symbols for everything I use in the OpenCL API.
I was able to build a "trivial" C program and link it using the .a file that I generated and gcc from mingw (not from the Haskell install). I'm using the latest windows release of the Haskell platform.
These are the steps I used for generating the .a file:
http://forums.amd.com/forum/messageview.cfm?catid=390&threadid=138890
I used the commands in the example script (e.g., gendef and dlltool). I've tried to use 32bit everything as much as possible, as I know that GHC will want everything to be 32bit, so I don't think it's a 32bit vs. 64bit issue.
Does anyone know if there is something different about invoking gcc under ghc instead of the gcc that I get from mingw?
I've also played with the ghc command line (I used cabal-dev --verbose=3 to inspect the command line) and I'm still unable to massage it into a working state.
Any help would be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
OpenCL 使用 stdcall 约定,但
OpenCLRaw
正在使用ccall
。这会产生几个问题。主要的一点是链接器希望函数名称符号以 @NN 结尾,其中 NN 取决于函数。事实证明,生成 libOpenCL.a 的正确方法如下(从 mingw shell):
这将生成 ghc 可以正确用于链接的 libOpenCL.a,但前提是 OpenCLRaw 修改为使用 stdcall 而不是 ccall。
现在我了解了问题,我可以修复 OpenCLRaw 绑定以在 Windows 上执行正确的操作。
当我使用 pexports 而不是 gendef 时,我能够从符号名称中删除 @NN,但随后生成的程序开始出现段错误。这是因为找到了符号,但调用约定不正确,可能导致堆栈损坏。
对我来说,主要的教训是您的 FFI 绑定必须与您的 C 库的调用约定相匹配。
OpenCL uses the stdcall convention, but
OpenCLRaw
is usingccall
. This creates several issues. The main one being that the linker wants the function name symbols to end in @NN where NN depends on the function.As it turns out, the correct way to generate libOpenCL.a is as follows (from a mingw shell):
This will generate libOpenCL.a that ghc can correctly use for linking, but only if OpenCLRaw is modified to use stdcall instead of ccall.
Now that I understand the problem I can fix the
OpenCLRaw
bindings to do the right thing on Windows.When I used pexports instead of gendef, I was able to remove the @NN from the symbol names, but then the resulting program started to segfault. This is because the symbol was found but the calling convention was incorrect, probably leading to corrupted stacks.
The main lesson for me is that your FFI binding must match your C library's calling convention.