如何使用 Xcode LLVM 编译器编译并使用 Haskell 作为 C 库?

发布于 2024-11-02 00:48:31 字数 1826 浏览 0 评论 0原文

我想建立一个项目来获取我的 .hs 代码和我的主 .c 程序,并通过使用 LLVM 编译器生成静态链接的可执行文件。我可以通过 ghc 命令行选项来构建 .hs、生成存根,并完全使用 ghc 编译和链接驱动程序应用程序。然而,我在 Xcode 中遇到了各种问题。

我的第一个问题是我当然需要在 Xcode 中使用 32 位编译环境。这解决了,我不得不摆弄路径来显式包含 HsFFI.h。这解决了,我得到一个链接器错误:

Ld "build/Debug/FFI Test.app/Contents/MacOS/FFI Test" normal i386
    cd "/Users/rcl/TestXCodeProjects/FFI Test"
    setenv MACOSX_DEPLOYMENT_TARGET 10.6
    /Developer/usr/bin/clang -arch i386
        -isysroot /Developer/SDKs/MacOSX10.6.sdk
        "-L/Users/rcl/TestXCodeProjects/FFI Test/build/Debug"
        "-L/Users/rcl/TestXCodeProjects/FFI Test/FFI Test"
        "-F/Users/rcl/TestXCodeProjects/FFI Test/build/Debug"
        -filelist "/Users/rcl/TestXCodeProjects/FFI Test/build/FFI Test.build/
            Debug/FFI Test.build/Objects-normal/i386/FFI Test.LinkFileList"
        -mmacosx-version-min=10.6 -framework Cocoa
        "/Users/rcl/TestXCodeProjects/FFI Test/FFI Test/ForeignExportCost.a"
        -o "/Users/rcl/TestXCodeProjects/FFI Test/build/Debug/FFI Test.app/
            Contents/MacOS/FFI Test"

Undefined symbols for architecture i386:
  "_hs_init", referenced from:
      -[FFI_TestAppDelegate applicationDidFinishLaunching:] in FFI_TestAppDelegate.o
  "_simpleFunction", referenced from:
      -[FFI_TestAppDelegate applicationDidFinishLaunching:] in FFI_TestAppDelegate.o
  "_hs_exit", referenced from:
      -[FFI_TestAppDelegate applicationDidFinishLaunching:] in FFI_TestAppDelegate.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

“simpleFunction”位于“ForeignExportCost.a”库中,我使用 ghc 进行编译,如下所示:

ghc -no-hs-main -fPIC -c ForeignExportCost.hs
ghc -no-hs-main -shared ForeignExportCost.o -o ForeignExportCost.a

我错过了什么或做错了什么?

I want to set up a project to take my .hs code, and my main .c program, and result in a statically linked executable through the use of LLVM compiler. I can get things working via ghc command line options to build a .hs, produce the stubs, and compile and link a driver application using ghc entirely. However, I get various issues within Xcode.

My first issue was that I of course need to use 32 bit compiling environment in Xcode. That solved, I had to fiddle with paths to explicitly include the HsFFI.h. That solved, I get a linker error:

Ld "build/Debug/FFI Test.app/Contents/MacOS/FFI Test" normal i386
    cd "/Users/rcl/TestXCodeProjects/FFI Test"
    setenv MACOSX_DEPLOYMENT_TARGET 10.6
    /Developer/usr/bin/clang -arch i386
        -isysroot /Developer/SDKs/MacOSX10.6.sdk
        "-L/Users/rcl/TestXCodeProjects/FFI Test/build/Debug"
        "-L/Users/rcl/TestXCodeProjects/FFI Test/FFI Test"
        "-F/Users/rcl/TestXCodeProjects/FFI Test/build/Debug"
        -filelist "/Users/rcl/TestXCodeProjects/FFI Test/build/FFI Test.build/
            Debug/FFI Test.build/Objects-normal/i386/FFI Test.LinkFileList"
        -mmacosx-version-min=10.6 -framework Cocoa
        "/Users/rcl/TestXCodeProjects/FFI Test/FFI Test/ForeignExportCost.a"
        -o "/Users/rcl/TestXCodeProjects/FFI Test/build/Debug/FFI Test.app/
            Contents/MacOS/FFI Test"

Undefined symbols for architecture i386:
  "_hs_init", referenced from:
      -[FFI_TestAppDelegate applicationDidFinishLaunching:] in FFI_TestAppDelegate.o
  "_simpleFunction", referenced from:
      -[FFI_TestAppDelegate applicationDidFinishLaunching:] in FFI_TestAppDelegate.o
  "_hs_exit", referenced from:
      -[FFI_TestAppDelegate applicationDidFinishLaunching:] in FFI_TestAppDelegate.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The "simpleFunction" is in "ForeignExportCost.a" library which I compile using ghc like this:

ghc -no-hs-main -fPIC -c ForeignExportCost.hs
ghc -no-hs-main -shared ForeignExportCost.o -o ForeignExportCost.a

What am I missing or doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨落画卷 2024-11-09 00:48:31

呃 - 看起来我的问题的答案是详细信息,告诉我如何痛苦地添加一个我的项目中有大量 .a。 这篇博文给出了一些有用的提示来帮助您上路。

尽管如果有人告诉我“嘿等等,有一种比迭代找出失败的部门更简单的方法”那就太棒了。因为我想多次重用这个框架,而这是一种让事情顺利进行的真正痛苦的方法!

Ugh - it looks like the answer to my question is detailed here, telling me how to painfully add a ton of .a's to my project. And this blog post gave some helpful tips to getting on the way.

Although if someone tells me "hey wait, there's an easier way than iteratively figuring out failed deps" that would be awesome. Because I want to reuse this framework several times and this is a real pain of a way to get things up and going!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文