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

| 我想建立一个项目来接收我的.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
我想念什么或做错什么?
已邀请:
gh-这里似乎很详细地回答了我的问题,告诉我如何在我的项目中痛苦地添加大量.a \。这篇博客文章提供了一些实用的技巧。 尽管如果有人告诉我“嘿,等等,还有比迭代找出失败的部门更简单的方法”,那真是太棒了。因为我想多次重用此框架,所以这是使事情不断发展的真正痛苦!

要回复问题请先登录注册