Reputation: 116
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.
Upvotes: 3
Views: 1643
Reputation: 116
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.
Upvotes: 6