[Haskell-cafe] Problems using ghc 7.8.2 with options -staticlib and -threaded on osx

27 views
Skip to first unread message

Frode Nerbråten

unread,
Jun 9, 2014, 2:36:48 PM6/9/14
to haskel...@haskell.org
Hi,

I'm having trouble building my Haskell library with GHC 7.8.2 and
Cabal 1.20.0.2 on OSX 10.9.3 with both -staticlib and -threaded
enabled.

The library I'm building exports several functions using FFI to be
called from ObjectiveC in an Xcode project. This works fine with just
-staticlib enabled, but now I realize I need to call into my Haskell
library from multiple OS-threads simultaneously. But when I add
-threaded to ghc-options I get an error when linking:

error: libtool: can't locate file for: -lpthread
error: libtool: file: -lpthread is not an object file (not allowed
in a library)

The linker command that fails looks like this (... replaces a bunch of
-l and -L options):

libtool -static -o liba.a dist/build/HsCocoa.o ... -lCffi -lpthread

In /usr/lib I have a libpthread.dylib that links to libSystem.dylib,
but no libpthread.a. I was under the impression that libpthread was
included with the system install.

Is this supposed to work or am I misunderstanding something basic? :)
Any help would be greatly appreciated!

The project source is available on github:
https://github.com/froden/digipostarkiv
(I asked the same question on stackoverflow:
http://stackoverflow.com/q/24096257/777411)

Best regards,
Frode Nerbråten
_______________________________________________
Haskell-Cafe mailing list
Haskel...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Bob Ippolito

unread,
Jun 9, 2014, 3:33:37 PM6/9/14
to Frode Nerbråten, haskell-cafe
This seems like a bug, you shouldn't need to link to libpthread at all on Mac. /usr/lib/libpthread.dylib is just a symlink to libSystem… Not sure how to get around the issue without rebuilding GHC, it looks like iOS is special cased in the compiler (OSiOS) but not Mac OS X (OSDarwin) [1]. 

Bob Ippolito

unread,
Jun 9, 2014, 3:49:29 PM6/9/14
to Frode Nerbråten, haskell-cafe
After patching your Xcode project file to use $(PROJECT_DIR) instead of /Users/frode/dev/haskell/digipostarkiv I was able to build this. I changed the "libtool command" in my lib/ghc-7.8.2/settings to a shim that removes -lpthread and then calls /usr/bin/libtool. Not pretty but it worked, I'm sure there's a better workaround, but I think the real solution should be to simply special-case OSDarwin in the same way as OSiOS in GHC.

Frode Nerbråten

unread,
Jun 10, 2014, 5:16:06 AM6/10/14
to Bob Ippolito, haskell-cafe
Thank you Bob! I tried your workaround (and fixed the lib path in my
project) and it worked perfectly. Calling my Haskell functions from
multiple ObjectiveC threads now works as expected. You saved my day :)

I'll report this as a bug in GHC. Thank you for the source link.

Regards,
Frode

Frode Nerbråten

unread,
Jun 10, 2014, 6:26:48 AM6/10/14
to Bob Ippolito, haskell-cafe
Reply all
Reply to author
Forward
0 new messages