How to compile static library with -fPIC from boost.python(如何使用 boost.python 中的 -fPIC 编译静态库)
问题描述
默认情况下,libboostpython.a
是在没有 -fPIC
的情况下编译的.但我必须制作一个 python 扩展,它是一个动态库,带有 -fPIC
链接到静态库.如何使用 boost.python
中的 -fPIC
编译静态库 (libboostpython.a
)?
By default, libboostpython.a
is compiled without -fPIC
. But I have to make a python extension and it is a dynamic library with -fPIC
that links to static libraries.
How can I compile a static library (libboostpython.a
) with -fPIC
from boost.python
?
推荐答案
您可以使用以下几个选项:
There are a couple options you could use:
- 从源代码编译 boost 并将额外的编译器选项传递给 bjam.例如.
bjam ... cxxflags='-fPIC'
.这会将每个 boost 源文件编译为位置无关代码. - 以共享库的形式使用boost.在这种情况下,您可能希望随应用程序一起提供 boost 共享库,以确保使用适当版本的 boost.您可以使用
'-Wl,-rpath,$ORIGIN'
标志链接您的可执行文件,这样当动态链接器搜索您的可执行文件所需的共享库时,它会在可执行文件所在的目录中查找它们.请参阅man ld.so有关$ORIGIN
的更多详细信息.
- Compile boost from source and pass extra compiler options to bjam. E.g.
bjam ... cxxflags='-fPIC'
. That would compile every boost source file as position independent code. - Use boost in the form of shared libraries. In this case you probably want to ship boost shared libraries along with your application to make sure the appropriate version of boost is used. You can link your executable with
'-Wl,-rpath,$ORIGIN'
flag, so that when the dynamic linker searches for shared libraries required by your executable it looks for them in the directory where the executable is. See man ld.so for more details on$ORIGIN
.
这篇关于如何使用 boost.python 中的 -fPIC 编译静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 boost.python 中的 -fPIC 编译静态库


基础教程推荐
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 常量变量在标题中不起作用 2021-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01