如何对蟒蛇路段C的lib在Windows下嵌入? [英] How to link C lib against python for embedding under Windows?

查看:190
本文介绍了如何对蟒蛇路段C的lib在Windows下嵌入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一C.应用程序的一部分的应用程序应该嵌入蟒蛇并没有我目前的问题。我尝试我的源链接到Python库,但它不能正常工作。

当我使用MinGW的我创建从dlltool python26.lib的python26.a文件,并将*某文件中的 C:/ Program Files文件(x86)的/python/2.6/libs

所以,我用此命编译文件:

 的gcc -o -shared mod_python.dll mod_python.o-LC:\\ Program Files文件(x86)的\\ python的\\ 2.6 \\库-lpython26轮候册, - 出IMPLIB ,libmod_python.a轮候册, - 输出画质,mod_python.def

和我得到这些错误:

 创建库文件:libmod_python.a
mod_python.o:在功能`宏module_init:
mod_python.c:34:未定义的参考`__imp__Py_Initialize
mod_python.c:35:未定义的参考`__imp__PyEval_InitThreads
... 等等 ...


  • 我的Python的根文件夹是 C:\\ Program Files文件(x86)的\\ python的\\ 2.6

  • 的Devsystem是在Windows Server 2008

  • GCC信息:从C规格阅读:/程序文件(x86)/ Mi​​nGW的/ bin中/../ lib中/ GCC / mingw32的/ 3.4.5 /规格
    $ P - ../gcc-3.4.5-20060117-3/configure --with-GCC --with-GNU-LD --with-GNU-作为主机= mingw32的--target = mingw32的:与配置$ PFIX = / MinGW的--enable-线程--disable-NLS --enable-语言= C,C ++,F77,ADA,objc,JAVA --disable-Win32的注册表--disable共享--enable-sjlj-例外--enable---disable的libgcj-java的AWT --without-X --enable-java的GC =伯姆--disable-libgcj里调试--enable-间preTER --enable-散列同步--enable-libstdcxx调试
    线程模型:的Win32
    gcc版本3.4.5(MinGW的,Vista的特殊R3)

我做什么错了?我怎么把它编译和链接: - ?)

干杯,格里高尔


编辑:
我忘了写我的Python安装的信息:这是官方的python.org安装2.6.1

...我如何创建python.a文件:

  dlltool -z python.def --export-全符号-v C:\\ WINDOWS \\ SYSTEM32 \\ python26.dlldlltool --dllname C:\\ WINDOWS \\ SYSTEM32 \\ python26.dll --def python.def -v --output-lib中python26.a


解决方案

那么在Windows上的Python分发版已经与 libpython26.a 在库子目录所以不需要生成 .A 使用的DLL文件的工具。

我也尝试用一个C文件toto.c一个小例子:

 的gcc -o -shared ./toto.dll ./toto.c -I / Python26 /有/ -L / Python26 /库-lpython26

和它的工作原理就像一个魅力。希望这将有助于: - )

I am working on an application written in C. One part of the application should embed python and there is my current problem. I try to link my source to the Python library but it does not work.

As I use MinGW I have created the python26.a file from python26.lib with dlltool and put the *.a file in C:/Program Files (x86)/python/2.6/libs.

Therefore, I compile the file with this command:

gcc -shared -o mod_python.dll mod_python.o "-LC:\Program Files (x86)\python\2.6\libs" -lpython26 -Wl,--out-implib,libmod_python.a -Wl,--output-def,mod_python.def

and I get those errors:

Creating library file: libmod_python.a
mod_python.o: In function `module_init':
mod_python.c:34: undefined reference to `__imp__Py_Initialize'
mod_python.c:35: undefined reference to `__imp__PyEval_InitThreads'
... and so on ...

  • My Python "root" folder is C:\Program Files (x86)\python\2.6
  • The Devsystem is a Windows Server 2008
  • GCC Information: Reading specs from C:/Program Files (x86)/MinGW/bin/../lib/gcc/mingw32/3.4.5/specs Configured with: ../gcc-3.4.5-20060117-3/configure --with-gcc --with-gnu-ld --with-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry --disable-shared --enable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x --enable-java-gc=boehm --disable-libgcj-debug --enable-interpreter --enable-hash-synchronization --enable-libstdcxx-debug Thread model: win32 gcc version 3.4.5 (mingw-vista special r3)

What I do wrong? How I get it compiled and linked :-)?

Cheers, gregor


Edit: I forgot to write information about my Python installation: It's the official python.org installation 2.6.1

... and how I created the python.a file:

dlltool -z python.def --export-all-symbols -v c:\windows\system32\python26.dll

dlltool --dllname c:\Windows\system32\python26.dll --def python.def -v --output-lib python26.a

解决方案

Well on Windows the python distribution comes already with a libpython26.a in the libs subdir so there is no need to generate .a files using dll tools.

I did try a little example with a single C file toto.c:

gcc -shared -o ./toto.dll ./toto.c -I/Python26/include/ -L/Python26/libs -lpython26

And it works like a charm. Hope it will help :-)

这篇关于如何对蟒蛇路段C的lib在Windows下嵌入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆