4

我想将Python 3.3解释器嵌入到Mac OS 10.9 Cocoa 应用程序中以添加一些 Python 功能。从我从另一个 StackOverflow 问答中读到的内容,最好创建一个静态库(页脚中的引用)而不是动态库。

这是我尝试从 Python 解释器创建静态库(.a 文件)的内容:

  1. 我已经从这里下载了 Python 3.3 (CPython) 源代码。
  2. 我已经*static*Modules/Setup.dist文件中添加了
  3. 我输入了以下内容来编译终端中的源代码:
    • ./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 实际上在 Mavericks 中被 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.a


4

2 回答 2

0

我认为它默认构建一个静态库,在基于 Unix 的平台上,包括 OSX。也就是说,只需简单的配置、制作、制作安装。它对我有用并构建了 libpython3.4m.a。但是您可能会考虑使用 --prefix 并阅读有关在 OSX 上安装多个版本的 Python 的信息。

你引用的线程是旧的?

嵌入并不奇怪,否则 Python 文档和书籍不会深入讨论它。

于 2014-05-21T21:05:27.907 回答
0

从 python 3.5 开始,在配置时无需使用 LDFLAGS 或 CPPFLAGS。

使用 configure --disable-shared 标志,它将构建一个静态库。

使用 configure --enable-shared 标志,它将构建一个动态库。

结合 --prefix,您可以使用所需的所有包设置您自己的 python 发行版。您可以同时拥有一个静态 python 库来合并到您的应用程序中,也可以拥有一个动态库来让交互式 python 正确启动。

于 2016-07-22T10:34:02.107 回答