静态编译Python解释器? [英] Compile the Python interpreter statically?
问题描述
我正在构建一个专用的嵌入式Python解释器,并希望避免依赖于动态库,所以我想用静态库来编译解释器(例如 libc.a
不要 libc.so
)。
我也想静态链接所有的动态库Python标准库。我知道这可以使用 Freeze.py
,但是有一个替代方法,这样可以在一个步骤完成。
我发现这个(主要是关于Python模块的静态编译):
- a href =http://bytes.com/groups/python/23235-build-static-python-executable-linux =nofollow noreferrer> http://bytes.com/groups/python/23235-build -static-python-executable-linux
这里描述了用于配置的文件:
< Python_Source> / Modules / Setup
b $ b
如果此文件不存在,可以通过复制创建:
< Python_Source> / Modules / Setup.dist
设置
文件有大量的文档,并且源中包含的 README
也提供了很多好的编译信息。
我还没有尝试编译,但我认为与这些资源,我应该成功,当我尝试。
更新
要获得纯静态的python可执行文件,您还必须配置如下:
./ configure LDFLAGS = - static -static-libgccCPPFLAGS = - static
一旦你使用这些标志生成后,你可能会收到很多有关重命名的警告,因为库isn存在。这意味着您尚未正确配置 Modules / Setup
并需要:
a)添加一行靠近顶部)像这样:
* static *
(星号/星号单词static和星号没有空格)
b)取消注释所有模块您希望可以静态使用(如math,array等)
您可能还需要添加特定的链接器标记以上)。到目前为止,我的经验是图书馆在没有修改的情况下工作。
运行make可能会有所帮助,如下所示:
make 2>& 1 | grep'renaming'
这将显示由于静态链接而无法编译的所有模块。 / p>
I'm building a special-purpose embedded Python interpreter and want to avoid having dependencies on dynamic libraries so I want to compile the interpreter with static libraries instead (e.g. libc.a
not libc.so
).
I would also like to statically link all dynamic libraries that are part of the Python standard library. I know this can be done using Freeze.py
, but is there an alternative so that it can be done in one step?
I found this (mainly concerning static compilation of Python modules):
Which describes a file used for configuration located here:
<Python_Source>/Modules/Setup
If this file isn't present, it can be created by copying:
<Python_Source>/Modules/Setup.dist
The Setup
file has tons of documentation in it and the README
included with the source offers lots of good compilation information as well.
I haven't tried compiling yet, but I think with these resources, I should be successful when I try. I will post my results as a comment here.
Update
To get a pure-static python executable, you must also configure as follows:
./configure LDFLAGS="-static -static-libgcc" CPPFLAGS="-static"
Once you build with these flags enabled, you will likely get lots of warnings about "renaming because library isn't present". This means that you have not configured Modules/Setup
correctly and need to:
a) add a single line (near the top) like this:
*static*
(that's asterisk/star the word "static" and asterisk with no spaces)
b) uncomment all modules that you want to be available statically (such as math, array, etc...)
You may also need to add specific linker flags (as mentioned in the link I posted above). My experience so far has been that the libraries are working without modification.
It may also be helpful to run make with as follows:
make 2>&1 | grep 'renaming'
This will show all modules that are failing to compile due to being statically linked.
这篇关于静态编译Python解释器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!