嵌入Python 3.3

0 投票
2 回答
688 浏览
提问于 2025-04-17 16:39

我尝试按照这里的说明来嵌入Python 3.3。

我使用的是MacOS 10.8,系统自带Python 2.7,所以我从python.org下载了Python 3.3的二进制版本。从中我获取了所有的头文件和“Python”文件,并把它重命名为“python33”,这样就不会和已安装的“Python”库冲突。我把所有文件放进了一个文件夹里:

embed.c /include python33

运行“file python33”命令后显示:

python33 (for architecture i386):   Mach-O dynamically linked shared library i386
python33 (for architecture x86_64): Mach-O 64-bit dynamically linked shared library x86_64

而embed.c的内容是:

#include <Python.h>

int
main(int argc, char *argv[])
{
  Py_Initialize();
  PyRun_SimpleString("print 'test'\n");
  Py_Finalize();
  return 0;
}

但是当我执行“gcc embed.c -I./include -L. -lpython33”时,它出现了错误:

ld: library not found for -lpython33

请问,有人知道怎么才能让它编译成功吗?

2 个回答

0

运行 python3.3-config --cflags 这个命令,你就能得到你系统所需的编译标志(cflags)。如果你想要链接标志(ldflags),可以用 python3.3-config --ldflags 这个命令。

0

首先,这个库的名字必须是'libxxx.so'的格式,这样链接器才能通过'-L. -lxxx'找到它。

即便如此,生成的可执行文件也不能直接使用,因为你不仅需要复制或创建这个库,还需要整个框架。

更多内容请查看:http://lists.apple.com/archives/cocoa-dev/2013/Feb/msg00522.html

撰写回答