Embedding Python 3.3

假装没事ソ 提交于 2020-01-06 07:34:30

问题


I try to embed Python 3.3, as described here.

I'm on MacOS 10.8 which has Python 2.7 so I downloaded binary distribution of version 3.3 from python.org. From it I got all the headers and "Python" which I renamed to "python33" so it wont collide with installed "Python" lib. I put everything into a folder:

embed.c /include python33

"file python33" says:

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

and embed.c is:

#include <Python.h>

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

But when I do "gcc embed.c -I./include -L. -lpython33" it breaks with:

ld: library not found for -lpython33

Please, does anyone know how to make it compile?


回答1:


Run python3.3-config --cflags and you'll get the needed cflags for your system. For ldflags, the command is python3.3-config --ldflags




回答2:


First and formost, the library has to be named in the form of 'libxxx.so', then the linker will find it with '-L. -lxxx'.

Even then, the resulting executable wont work as one has to copy/create not just the library but the whole framework.

More here: http://lists.apple.com/archives/cocoa-dev/2013/Feb/msg00522.html



来源:https://stackoverflow.com/questions/15007309/embedding-python-3-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!