[Haskell-cafe] Template Haskell and packages using Obj-C FFI

Hiromi ISHII konn.jinro at gmail.com
Thu Aug 27 04:55:13 UTC 2015


Hi cafe,

I'm currently writing objc specific marshaller for inline-c, and
faced with strange behaviour of Template Haskell and FFI.

It turns out that it's irrelevant to inline-c and matter of GHC.
Here is minimal example package for failure:

https://github.com/konn/objcth

This tiny package is built up with two parts:

1. A wrapper library to call NSLog function with Haskell's String value.
    This uses FFI interface,
2. An executable which calls the above library to say hello.

If 2. does not contain any Template Haskell macros, everything works fine.
But if any TH macro presents, even only top level splice `$(return [])`, then
compiler halts with following error:

```
<command line>: can't load .so/.DLL for: /Users/myname/Documents/Programming/Haskell/lab/ghcbugs/objcth/.stack-work/dist/x86_64-osx/Cabal-1.22.4.0/build/libHSobjcth-0.1.0.0-IBzJnZWD04lEmS0Ot4HRVO-ghc7.10.2.dylib (dlopen(/Users/myname/Documents/Programming/Haskell/lab/ghcbugs/objcth/.stack-work/dist/x86_64-osx/Cabal-1.22.4.0/build/libHSobjcth-0.1.0.0-IBzJnZWD04lEmS0Ot4HRVO-ghc7.10.2.dylib, 5): Symbol not found: _OBJC_CLASS_$_NSString
  Referenced from: /Users/myname/Documents/Programming/Haskell/lab/ghcbugs/objcth/.stack-work/dist/x86_64-osx/Cabal-1.22.4.0/build/libHSobjcth-0.1.0.0-IBzJnZWD04lEmS0Ot4HRVO-ghc7.10.2.dylib
  Expected in: flat namespace
 in /Users/myname/Documents/Programming/Haskell/lab/ghcbugs/objcth/.stack-work/dist/x86_64-osx/Cabal-1.22.4.0/build/libHSobjcth-0.1.0.0-IBzJnZWD04lEmS0Ot4HRVO-ghc7.10.2.dylib)

```

I used stack to build automatically, but cabal-install produces almost the same
result (modulo paths to dist files).

TH uses GHCi internally, so perhaps it's related to GHCi?
If I replace the call for NSLog and [NSSring stringWith...] with puts c-function,
everything gets fine.

Is there any workaround, or it's the bug of GHC?

Here is my environment:

* OS X Yosemite 10.10.5
* Haskell Platform 7.10.2a
* llvm-3.5 (installed via brew install llvm35)

$ tail -n3  /Library/Frameworks/GHC.framework/Versions/7.10.2-x86_64/usr/lib/ghc-7.10.2/settings
, ("LLVM llc command","llc-3.5")
, ("LLVM opt command","opt-3.5")
]


-- Hiromi ISHII
konn.jinro at gmail.com



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 496 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150827/af976157/attachment.sig>


More information about the Haskell-Cafe mailing list