静态链接使用C ++包装器库的haskell程序

时间:2014-04-19 20:50:45

标签: haskell static-linking

我正在尝试制作一个程序,通过一些第三方模块,依赖于icu库。我怀疑依赖是通过Network.HTTP.Conduit,但可能是通过别的东西。动态链接的二进制文件即使在相同发行版的相邻版本之间也不可移植,因为libicu *具有不兼容的不同版本。

所以我试图静态地构建程序:

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

我收到了很多这类错误:

/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

我相信我拥有所有相关库的静态版本(libiculibstdc++)。似乎链接器没有提供libstdc++(或者它是libitl?显然,后者定义了违规函数。

我尝试将选项-optl-static-libstdc++-optl-lstdc++-optl-litm添加到命令行的末尾无效。

静态链接间接依赖于C ++支持函数的haskell程序的过程是什么?我正在运行

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

gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2

修改 我将问题缩小到包Data.Text.ICU,这是一个无法构建到静态可执行文件中的简短程序:

{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.Text.ICU
main = print $ toUpper Current "Hello!"

1 个答案:

答案 0 :(得分:4)

问题归结为gcc实际上没有libstdc ++,或其他可用的核心c ++库,但g++确实存在。

要求ghc使用g++代替gcc进行链接应该可以解决问题。将以下内容添加到您的cabal文件中作为ghc-options下的参数:-pgml g++。它将链接程序设置为g++,这应该允许系统链接器找到它需要的库。

相关问题