Cabal vs. C++

Roman Leshchinskiy rl at
Tue Feb 26 06:09:47 EST 2008

Thomas Schilling wrote:
> On 26 feb 2008, at 09.38, Roman Leshchinskiy wrote:
>> What is the simplest way to build a Haskell project that uses a C++ 
>> library? It needs at least the following from Cabal.
>>   - It must know how to compile C++ files. This kind of works by
>>     accident if I list those under c-sources since gcc knows what to do
>>     with them but this is (a) ugly and (b) doesn't allow me to pass
>>     C++-specific options to gcc.
>>   - The project must be linked with g++. However, I don't understand how
>>     to tell Cabal which linker to use. I got as far as
>>       main = defaultMainWithHooks
>>            $ defaultUserHooks
>>               { hookedPrograms = [Program "ld" (findProgramOnPath "g++")
>>                                                (\_ _ -> return Nothing)]
>>     but this doesn't seem to work. configure --with-ld=g++ does, but
>>     it's not nice.
> I don't think you need to link with g++.  I successfully linked to a C++ 
> library by adding -fexceptions to the linker options.  I used a 
> makefile, but this should work with Cabal as well.

Constructors for static objects won't get run unless you link with g++ 
(which, IIRC, uses collect2 for linking). Just adding -fexceptions isn't 
enough. As a matter of fact, what I'd really want is to use the standard 
C++ compiler for linking, whatever that is.


More information about the Libraries mailing list