Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Statically link a haskell program that uses C++ wrapper library

I am trying to make a program that, via some of the third party modules, is dependant upon icu library. I suspect that the dependency is via Network.HTTP.Conduit but maybe via something else. Dynamically linked binary is not portable even between adjacent versions of the same distribution because libicu* are of different versions that are not compatible.

So I am trying to build the program statically:

$ ghc --make -static -optc-static -optl-static my-prog.hs -optl-pthread

and I am getting a lot of errors of this kind:

/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libicuuc.a(dictionarydata.ao):(.data.rel.ro._ZTIN6icu_5222BytesDictionaryMatcherE[_ZTIN6icu_5222BytesDictionaryMatcherE]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libicuuc.a(dictionarydata.ao):(.data.rel.ro._ZTVN6icu_5217DictionaryMatcherE[_ZTVN6icu_5217DictionaryMatcherE]+0x28): undefined reference to `__cxa_pure_virtual'
collect2: error: ld returned 1 exit status

I believe that I have static versions of all involved libraries (libicu, libstdc++). It seems as if the linker has not been supplied with libstdc++ (or is it libitl? Apparently the offending functions are defined in the latter).

I tried adding the options -optl-static-libstdc++, -optl-lstdc++ and -optl-litm to the end of the command line to no avail.

What is the procedure to statically link a haskell program that is indirectly dependent on C++ support functions? I am running

The Glorious Glasgow Haskell Compilation System, version 7.6.3
gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1

or

gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2

Edit: I narrowed the problem to the package Data.Text.ICU, and here is a short program that cannot be built into a static executable:

{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.Text.ICU
main = print $ toUpper Current "Hello!"
like image 922
crosser Avatar asked Apr 19 '14 20:04

crosser


1 Answers

The problem boils down to the fact that gcc doesn't actually have libstdc++, or the other core c++ libraries available to it, but g++ does.

Asking ghc to use g++ instead of gcc for linking should do the trick. Add the following to your cabal file as a parameter under ghc-options: -pgml g++. It sets the linking program to g++ which should allow the system linker to find the libraries it needs.

like image 141
cassandracomar Avatar answered Oct 03 '22 07:10

cassandracomar