Compile the Python interpreter statically
来源:互联网 发布:监控端口号 编辑:程序博客网 时间:2024/06/11 08:48
Q:
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 libs instead (eg libc.a not libc.so).
I would also like to statically link all dynamic libraries that are part of the Python standard library as well. 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):
- http://bytes.com/groups/python/23235-build-static-python-executable-linux
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.
- Compile the Python interpreter statically
- Extending and Embedding the Python Interpreter contents
- no python interpreter configured for the project
- No python interpreter configured for the project
- The Python Tutorial 2——Using the Python Interpreter
- [译]The Python Tutorial#2. Using the Python Interpreter
- Python 官方文档学习笔记 topic2 Using the Python Interpreter
- Python学习日记(一)------------Using the Python Interpreter
- [Python教程]2. Using the Python Interpreter/使用解释器
- python compile
- 扩展和嵌入Python 解释器(Extending and Embedding the Python Interpreter)--摘要
- 扩展和嵌入Python 解释器(Extending and Embedding the Python Interpreter)--第一章
- 【python】在pycharm初次使用的时候出现错误:no python interpreter configured for the project
- No Python interpreter selected
- compile the form
- The PL/0 compiler/interpreter
- python内置函数compile
- python小点心--compile
- C#不安装Oracle10g客户端连接Oracle10g数据库【转】
- 使用jQuery内容过滤选择器选择元素
- 编程学习网站
- fedora18挂载点/分区设置的问题。
- JavaScript 组合模式
- Compile the Python interpreter statically
- 字符集和字符编码(Charset & Encoding)
- 双击程序没反应的解决办法之一
- iOS开发 应用启动速度的优化
- @Resource example
- Uva 11235 频繁出现的数值(RMQ-Sparse Table 算法)(训练指南)
- Fedora Linux的一些常用设置和常用命令
- HSM层次状态机实战
- Magento CMS分页功能实现