Statically linking a C library with a Haskell library <p>I have a Haskell project that aims to create some C++ bindings. I've written the C wrappers and compiled them into a stand-alone statically linked library. </p> <p>I'd like to write the Haskell bindings to link statically to the C wrappers so that I don't have to distribute the C wrappers separately but I can't seem to get it working and would appreciate some help.</p> <p>I specify the C library as an extra library but my <code>cabal build</code> step doesn't seem to add it to compile command.</p> <p>I've created a small project to illustrate this (<a href="http://github.com/deech/CPlusPlusBindings">http://github.com/deech/CPlusPlusBindings</a>).</p> <p>It contains a small C++ class (<a href="https://github.com/deech/CPlusPlusBindings/tree/master/cpp-src">https://github.com/deech/CPlusPlusBindings/tree/master/cpp-src</a>), the C wrapper (<a href="https://github.com/deech/CPlusPlusBindings/tree/master/c-src">https://github.com/deech/CPlusPlusBindings/tree/master/c-src</a>), a working C test routine (<a href="https://github.com/deech/CPlusPlusBindings/tree/master/c-test">https://github.com/deech/CPlusPlusBindings/tree/master/c-test</a>) and the Haskell file (<a href="https://github.com/deech/CPlusPlusBindings/blob/master/src/BindingTest.chs">https://github.com/deech/CPlusPlusBindings/blob/master/src/BindingTest.chs</a>).</p> <p>The C library is added in Setup.hs not in the Cabal file because that's how I have it my real project which builds the C library using "make" through Cabal just before the build stepf. I have verified that at the build step the <code>extraLibs</code> part of <code>BuildInfo</code> contains the library name and <code>extraLibDirs</code> contains the right directory. </p> <p>The output of my <code>cabal build</code> is:</p> <pre><code>creating dist/setup ./dist/setup/setup build --verbose=2 creating dist/build creating dist/build/autogen Building CPlusPlusBinding-0.1.0.0... Preprocessing library CPlusPlusBinding-0.1.0.0... Building library... creating dist/build /usr/local/bin/ghc --make -fbuilding-cabal-package -O -odir dist/build -hidir dist/build -stubdir dist/build -i -idist/build -isrc -idist/build/autogen -Idist/build/autogen -Idist/build -I/home/deech/Old/Haskell/CPlusPlusBinding/c-src -I/home/deech/Old/Haskell/CPlusPlusBinding/cpp-includes -optP-include -optPdist/build/autogen/cabal_macros.h -package-name CPlusPlusBinding-0.1.0.0 -hide-all-packages -package-db dist/package.conf.inplace -package-id base-4.6.0.1-8aa5d403c45ea59dcd2c39f123e27d57 -XHaskell98 -XForeignFunctionInterface BindingTest Linking... /usr/bin/ar -r dist/build/libHSCPlusPlusBinding-0.1.0.0.a dist/build/BindingTest.o /usr/bin/ar: creating dist/build/libHSCPlusPlusBinding-0.1.0.0.a /usr/bin/ld -x --hash-size=31 --reduce-memory-overheads -r -o dist/build/HSCPlusPlusBinding-0.1.0.0.o dist/build/BindingTest.o In-place registering CPlusPlusBinding-0.1.0.0... /usr/local/bin/ghc-pkg update - --global --user --package-db=dist/package.conf.inplace </code></pre> <p>Unfortunately neither the compilation nor the linking step uses the C library. There are no other warnings or errors.</p>