2
我想建立一个项目来获取我的.hs代码和我的主要.c程序,并通过使用LLVM编译器生成一个静态链接的可执行文件。我可以通过ghc命令行选项来创建一个.hs文件,生成存根,并使用ghc编译和链接驱动程序应用程序。但是,我在Xcode中遇到了各种问题。如何使用Xcode LLVM编译器编译并使用Haskell作为C库?
我的第一个问题是我当然需要在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”是在我编译使用GHC这样的“ForeignExportCost.a”库:
ghc -no-hs-main -fPIC -c ForeignExportCost.hs
ghc -no-hs-main -shared ForeignExportCost.o -o ForeignExportCost.a
我缺少什么或者做错了?
只是检查,但你*通过使用GHC作为C编译器支持的路径得到它的工作(a la http://www.haskell.org/haskellwiki/Calling_Haskell_from_C)? – 2011-04-18 21:37:37
是的,我能够 - 我使用的代码张贴在我的其他SO问题:http://stackoverflow.com/questions/5665209/performance-considerations-of-haskell-ffi-c虽然我不得不稍微改变他的编译行首先没有Driver.cpp;它生成了存根和东西,然后重新运行他给出的实际行。 – Nektarios 2011-04-18 21:39:01