如何通过GCC与libstdc ++ _ pic.a链接? [英] How to link with libstdc++_pic.a with GCC?

查看:129
本文介绍了如何通过GCC与libstdc ++ _ pic.a链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的系统上有一个libstdc ++ _ pic.a(Ubuntu 12.04,gcc 4.6.3),大概是使用-fPIC创建的libstdc ++版本.我也有一个libstdc ++.a.

I have a libstdc++_pic.a on my system (Ubuntu 12.04, gcc 4.6.3), presumably this is the version of libstdc++ created with -fPIC. I also have a libstdc++.a.

当我尝试通过-static-libstdc ++链接标志将libstdc ++与共享库静态链接时,出现以下错误:

I see the following error when I try to statically link libstdc++ with a shared library via the -static-libstdc++ link flag:

:-1: error: /usr/lib/gcc/x86_64-linux-gnu/4.6/libstdc++.a(functexcept.o): relocation R_X86_64_32 against `std::bad_exception::~bad_exception()' can not be used when making a shared object; recompile with -fPIC

:-1: error: /usr/lib/gcc/x86_64-linux-gnu/4.6/libstdc++.a(functexcept.o): relocation R_X86_64_32 against `std::bad_exception::~bad_exception()' can not be used when making a shared object; recompile with -fPIC

因此,我假设它使用的是非图片版本,就像我希望基于默认命名一样.如何指示链接器使用libstdc ++ _ pic.a文件?

So I'm assuming it is using the non pic version, as I would expect based on the default naming. How can I instruct the linker to use the libstdc++_pic.a file?

更新1 _pic版本位于/usr/lib/gcc/x86_64-linux-gnu/4.6/32的32位gcc子文件夹中,在64位版本所在的父文件夹中看不到_pic版本.看来我的gcc版本未使用64位PIC静态libstdc ++.a编译.

Update 1 The _pic version is in the 32 bit gcc subfolder at /usr/lib/gcc/x86_64-linux-gnu/4.6/32, and I don't see a _pic version in the parent folder where the 64 bit versions are located. It appears that my version of gcc was not compiled with a 64 bit PIC static libstdc++.a.

更新2 通过检查我的gcc版本,然后安装软件包,我能够安装libstdc ++ _ pic.a的64位版本:

Update 2 I was able to install the 64 bit version of libstdc++_pic.a by checking my gcc version and then installing the package:

gcc --version gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 sudo apt-get install libstdc++6-4.6-pic

gcc --version gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 sudo apt-get install libstdc++6-4.6-pic

现在我在/usr/lib/gcc/x86_64-linux-gnu/4.6/中看到它.仍然需要弄清楚如何告诉链接器使用它.

And now I see it in /usr/lib/gcc/x86_64-linux-gnu/4.6/. Still need to figure out how to tell linker to use it.

推荐答案

我似乎已经通过传递-nostdlib链接器选项,然后显式链接libstdc ++ _ pic来解决此问题.

I seem to have fixed this by passing the -nostdlib linker option, and then explicitly linking libstdc++_pic.

但是,现在出现以下错误:

However, now I am getting the following error:

version node not found for symbol std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::_M_move(wchar_t*, wchar_t const*, unsigned long)@@GLIBCXX_3.4.5

version node not found for symbol std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::_M_move(wchar_t*, wchar_t const*, unsigned long)@@GLIBCXX_3.4.5

研究之后,似乎可能存在带pic的静态libstdc ++ 64bit错误,现在已在较新版本的gcc(4.7.3)中解决.这个问题还有更多信息:

After researching it appears there may have been a bug for static libstdc++ 64bit with pic, which is now addressed in newer versions of gcc (4.7.3). This other question has more information:

在Linux上编译一个共享库以全部针对分布

这篇关于如何通过GCC与libstdc ++ _ pic.a链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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