我想将 Python 3.3 解释器嵌入到 Mac OS 10.9 Cocoa应用程序中,以添加一些Python功能。从我从另一个StackOverflow Q& A中读到的内容来看,最好是创建一个静态库(页脚中的引用)而不是动态库。
以下是我尝试使用Python解释器创建静态库(.a文件):
*static*
文件Modules/Setup.dist
./configure LDFLAGS="-static -static-libgcc" CPPFLAGS="-static"
我得到的结果如下:
checking build system type... x86_64-apple-darwin13.1.0
checking host system type... x86_64-apple-darwin13.1.0
checking for --enable-universalsdk... no
checking for --with-universal-archs... 32-bit
checking MACHDEP... darwin
checking for --without-gcc... no
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/Path/To/My/Source/Python-3.3.4':
configure: error: C compiler cannot create executables
See `config.log' for more details
我的理解是gcc实际上被小牛队的Apple LLVM 5.0(clang-500.2.79)(基于LLVM 3.3svn)所取代。
另外,我在 config.log ...
中找到了以下内容configure:3914: checking whether the C compiler works
configure:3936: clang -static conftest.c >&5
ld: library not found for -lcrt0.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
问题: 如何使用 Apple LLVM 编译Python 3.3,因此我有一个静态库,例如 libpython3.3。一个
答案 0 :(得分:0)
我认为默认是在基于Unix的平台上构建静态库,包括OSX。也就是说,只需简单配置,make,make install。它对我有用,并构建了libpython3.4m.a。但您可以考虑使用--prefix并阅读有关在OSX上安装多个版本的Python的信息。
您引用的主题是旧的吗?
嵌入并不是那么奇怪,否则Python文档和书籍就不会深入讨论。
答案 1 :(得分:0)
从python 3.5开始,在配置时不需要使用LDFLAGS和CPPFLAGS。
使用configure --disable-shared标志,它将构建一个静态库。
使用configure --enable-shared标志,它将构建一个动态库。
结合--prefix,您可以使用所需的所有包设置自己的python发行版。您既可以将静态python库合并到您的应用程序中,也可以使用动态库来使交互式python正常启动。