2

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?

Nektarios
  • 10,173
  • 8
  • 63
  • 93
  • Just checking, but you *did* get it working via the supported path of using GHC as the C compiler (a la http://www.haskell.org/haskellwiki/Calling_Haskell_from_C ) ? – Don Stewart Apr 18 '11 at 21:37
  • Yes I was able to - I'm using the code posted up in my other SO question: http://stackoverflow.com/questions/5665209/performance-considerations-of-haskell-ffi-c Although I had to slightly change his compilation line to first not have Driver.cpp; which generated the stubs and stuff, and then rerun the actual line he gives. – Nektarios Apr 18 '11 at 21:39

1 Answers1

2

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!

Nektarios
  • 10,173
  • 8
  • 63
  • 93