静态链接使用C ++包装库的haskell程序 [英] Statically link a haskell program that uses C++ wrapper library

查看:217
本文介绍了静态链接使用C ++包装库的haskell程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图制作一个程序,通过一些第三方模块,依赖于 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):未定义的引用`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):未定义引用`__cxa_pure_virtual'
collect2 :错误:ld返回1退出状态

我相信我有所有涉及库的静态版本( libicu libstdc ++ )。看起来好像链接器没有被提供 libstdc ++ (或者它是 libitl ?显然,违规函数被定义在后者中)。

我尝试添加选项 -optl-static-libstdc ++ -optl-lstdc ++ -optl-litm 到命令行的结尾无济于事。



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

  Glorious Glasgow Haskell编译系统,版本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其中
import Data .Text.ICU
main =打印$ toUpper当前Hello!


解决方案

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



要求 ghc 使用 g ++ 而不是 gcc 用于链接应该可以做到。将以下内容添加到您的cabal文件中作为ghc-options下的参数: -pgml g ++ 。它将链接程序设置为 g ++ ,这将允许系统链接程序找到它所需的库。


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!"

解决方案

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.

这篇关于静态链接使用C ++包装库的haskell程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆