如何强制Boost编译使用-fPIC [英] how to force compilation of Boost to use -fPIC

查看:545
本文介绍了如何强制Boost编译使用-fPIC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的团队产生了一个供Python使用的共享库.该库完全是C ++,我们使用Boost公开给python.因为我们不能保证客户安装了Boost库,所以我们将Boost所需的功能静态地拉到共享对象文件中.编译的最后阶段对许多人来说都是熟悉的

The team on which I work produces a shared library for use in Python. This library is entirely C++ and we use Boost to expose to python. Because we cannot guarantee that our clients have the Boost libraries installed, we pull in the functionality needed from Boost to the shared object file statically. The final stage in compilation will look familiar to many

g++ -o <output> <objects> -Wl,-Bstatic -lboost_python -lboost_regex ... -Wl,-Bdynamic -shared <other_opts>

传统上,我们使用自己构建的Boost:1.47.这个版本现在已经很旧了,因此我们希望进行更新.但是,奇怪的是,当我在CentOS 7系统上使用yum安装必要的对象时,我从gcc收到以下错误:

We've traditionally used our own build of Boost: 1.47. This version is now quite old and so we wish to update. However, oddly, when I install the necessary objects using yum on my CentOS 7 system, I get the following error from gcc:

relocation R_X86_64_32 against '.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC

好吧,我想我只是下载最新的Boost(CentOS 7将安装Boost 1.53)并自己构建.毕竟,这一直对我们有用.我遵循说明在这里,但是我遇到了同样的错误.我该如何强制-fPIC甚至为其构建的静态库使用它?

Well, I thought I'd simply download the latest boost (CentOS 7 installs Boost 1.53) and do my own build. This, after all, has always worked for us. I follow the instructions here but I got the same error. How do I force the use of -fPIC for even the static libraries that it builds?

推荐答案

我相信boost在编译共享库(.so文件)时会自动使用-fPIC,但是下面的命令在编译静态库时会使用-fPIC( .a文件).

I believe boost automatically uses -fPIC when compiling a shared library (.so file), but the below command uses -fPIC when compiling a static library (.a file) too.

这对我提升了1.46.1很有帮助:

This worked for me on boost 1.46.1:

sudo ./bjam cxxflags=-fPIC cflags=-fPIC -a ... install

...中,您可以添加其他标志,例如threading=multi--layout=tagged,还可以添加要构建的项目列表(例如:--with-regex).

The ... is where you add additional flags like threading=multi or --layout=tagged, and optionally the list of projects to build (for example: --with-regex).

注意:我不确定cflags是必需的,但似乎没有受到伤害.

Note: I'm not certain cflags is necessary, but it doesn't seem to hurt.

参考链接:

  • https://cmake.org/Wiki/TubeTK/Build_Instructions#Boost_.28optional.29
  • http://lists.boost.org/boost-users/2010/07/60682.php

这篇关于如何强制Boost编译使用-fPIC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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