问题描述
我建立嵌入式Python间preTER一个特殊用途,并希望避免在动态库的依赖关系,所以我想编译间preTER用,而不是静态库(如文件libc.a
不是 libc.so
)。
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
).
我也想静态链接是Python标准库的一部分,所有动态库。我知道这是可以做到用 Freeze.py
,但有一个替代,以便它可以在一个步骤中完成?
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?
推荐答案
我发现这个(主要是关于Python模块静态编译):
I found this (mainly concerning static compilation of Python modules):
表示所使用的位于此处的配置文件:
Which describes a file used for configuration located here:
<Python_Source>/Modules/Setup
如果没有present,它可以通过复制创建这个文件:
If this file isn't present, it can be created by copying:
<Python_Source>/Modules/Setup.dist
的设置
文件具有万吨文档中它和 README
包含在源代码提供了很多很好的编译信息也是如此。
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.
要得到一个纯静态的Python可执行文件,还必须配置如下:
To get a pure-static python executable, you must also configure as follows:
./configure LDFLAGS="-static -static-libgcc" CPPFLAGS="-static"
一旦你用这些标志启用后,你可能会得到很多的警告有关重命名,因为库不是present。这意味着你没有配置模块/设置
正确,需要:
A)添加一行(靠近顶部)是这样的:
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的跨preTER?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!