python编译成二进制执行_将Python3编译成可在m上执行的二进制

我将把Python3命令行程序编译成Mac OS X上的二进制可执行文件

我安装python3是用homebrew完成的,但当我尝试运行时

^{cd1>}

我得到以下错误:Apple LLVM version 8.0.0 (clang-800.0.42.1)

Target: x86_64-apple-darwin16.1.0

Thread model: posix

InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.12.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -disable-free -disable-llvm-verifier -discard-value-names -main-file-name at_analyzer.c -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu penryn -target-linker-version 274.1 -v -dwarf-column-info -debugger-tuning=lldb -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -I /usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/Headers -Os -fdebug-compilation-dir /Users/alex/Source/AT_analyzer -ferror-limit 19 -fmessage-length 150 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.12.0 -fencode-extended-block-signature -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o /var/folders/8l/3c5cnrvj1hg_qbr73dz1pnq40000gn/T/at_analyzer-e9d098.o -x c at_analyzer.c

clang -cc1 version 8.0.0 (clang-800.0.42.1) default target x86_64-apple-darwin16.1.0

ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/local/include"

ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/Library/Frameworks"

#include "..." search starts here:

#include <...> search starts here:

/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/Headers

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0/include

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks (framework directory)

End of search list.

"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.12.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -o at_analyzer /var/folders/8l/3c5cnrvj1hg_qbr73dz1pnq40000gn/T/at_analyzer-e9d098.o -lpython3.5m -lpthread -lm -lutil -ldl -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/8.0.0/lib/darwin/libclang_rt.osx.a

ld: library not found for -lpython3.5m

clang: error: linker command failed with exit code 1 (use -v to see invocation)

如有任何帮助,将不胜感激。

Python本身是一种解释型语言,它不需要像C、C++等那样通过编译生成二进制文件。但是,如果你要在其他平台上运行Python程序,比如在嵌入式设备或服务器上,这时可能需要对Python源码进行交叉编译。这是指在一个平台(通常是主机)上编译源码,然后生成可以在目标平台(如嵌入式设备)上运行的可执行文件。 Python交叉编译通常涉及到以下几个步骤: 1. **获取预构建的Python库**:首先,你需要为目标平台找到预构建的Python解释器库,例如`pycrt`或`python-embedded`等。 2. **选择合适的工具链**:这取决于你的目标平台,可能需要像`cross-build.sh`这样的工具来配置编译环境,或者是直接使用构建系统(如CMake或Autotools)。 3. **设置编译选项**:在配置过程中,指定要用到的架构、操作系统和其他特定选项。 4. **编译Python**:使用标准的编译命令(如`gcc`或`clang`),但可能会有额外的前缀(如`arm-linux-gnueabihf-gcc`)来指示目标架构。 5. **链接动态库**:对于Python的动态链接库,也需要进行相应的交叉编译,确保链接的目标库也是交叉编译版本的。 6. **测试和打包**:编译完成后,务必在目标平台上验证程序能否正常运行,并将其打包成可执行文件。 注意,不是所有的Python模块都能顺利地在所有平台上编译,尤其是那些依赖于非跨平台API或第三方库的模块。因此,预先评估并调整项目的依赖是很重要的。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值