Python嵌入C代码编译错误 [英] Python embedded C code compilation error

查看:147
本文介绍了Python嵌入C代码编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近购买了一台新电脑,并尝试将一个python项目从我的旧电脑移动到我的新电脑。 python项目使用一些directx9 C ++代码(使用#include )截取屏幕截图并编译这个C ++文件我使用G ++。



代码和安装G ++和Python后我发现我用来编译代码返回一个错误:

  g ++ -std = c ++ 11 -shared -IC:\Python27\include -LC:\Python27\libs ScreenShots / PictureStr.cpp -lpython27 -ld3d9 -lole32 -o ScreenShots / PictureStr.pyd 

返回:

  \Python27 \libs / libpython27.a:添加符号时出错:文件格式无法识别
collect2.exe:错误:ld返回1退出状态

(删除-ld3d9 -lole32不会改变任何东西)



我不知道为什么会发生这种情况不会发生在我尝试的任何其他计算机或我的旧电脑),我不能找到任何可能导致这种情况。



如果这是相关的我使用windows 10 64bit(在我的旧电脑和我的新电脑)。



也许我需要重新编译python libs或那个特定的文件,所以任何建议如何这也是非常感谢。



感谢您阅读,欢迎任何建议。




解决方案

我试图应对libpython27.a从我的旧电脑到我的新电脑,并尝试使用gcc再次和它工作,它似乎像新的64位python 2.7安装libpython27.a是破碎。如果有人遇到此问题,请尝试重新创建您的libpython27.a文件。



要重新创建libpython.a,请运行:

  pexportsC:\Windows\SysWOW64\python27.dll> C:\Python27\libs\python27.def
dlltool --dllnameC:\Windows \SysWOW64\python27.dll--defC:\Python27\libs \python27.def--output-libC:\Python27\libs\libpython27.a

其中 C:\ Python27 \ 是你的python文件夹,如果是32位计算机,应该是System32而不是SysWOW64。



要安装pexports install mingw并运行mingw-get install pexports。


I have recently bought a new computer and tried to move a python project from my old computer to my new one. The python project used some directx9 C++ code (with #include <Python.h>) to take screenshots and to compile this C++ file I used G++.

Without changing any of the code and after installing G++ and Python I found that what I used to compile the code returns an error:

    g++ -std=c++11 -shared -IC:\Python27\include -LC:\Python27\libs ScreenShots/PictureStr.cpp -lpython27 -ld3d9 -lole32 -o ScreenShots/PictureStr.pyd

returns this:

    C:\Python27\libs/libpython27.a: error adding symbols: File format not recognized
    collect2.exe: error: ld returned 1 exit status

(removing the -ld3d9 -lole32 doesn't change anything)

I have no idea why this happened (and doesn't happen on any other computer that I tried or my old computer) and I wasn't able to find anything that could cause this.

In case this is relevant I use windows 10 64bit (in both my old computer and my new one).

Perhaps I need to recompile the python libs or that specific file so any advice on how to do that is also greatly appreciated.

Thank you for reading this, any advice is welcome.

I found a solution, I answered bellow.

解决方案

I tried coping libpython27.a from my old computer to my new one and try using gcc again and it worked, it seems like the new 64bit python 2.7 installation libpython27.a is broken. If someone else runs into this problem, try recreating your libpython27.a file.

To recreate libpython.a run:

pexports "C:\Windows\SysWOW64\python27.dll" > "C:\Python27\libs\python27.def"
dlltool --dllname "C:\Windows\SysWOW64\python27.dll" --def "C:\Python27\libs\python27.def" --output-lib "C:\Python27\libs\libpython27.a"

Where C:\Python27\ is your python folder and should be System32 instead of SysWOW64 if it's a 32 bit computer.

To install pexports install mingw and run mingw-get install pexports.

这篇关于Python嵌入C代码编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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