Build SIP and PyGlobalShortcut for Windows

若如初见. 提交于 2020-03-22 10:58:26

问题


I am writing a Python2.7/PyQt4 programm under Ubuntu, but the application will be deployed on a Windows platform. One of the functions is that the application should capture several keystrokes (e.g. "Alt+A") even if it is not in focus/minimized. I use PyGlobalShortcut for this purpose, which is a Python/SIP wrapper around libxqt. Following the manual, I installed Qt4 + SIP and ran the pip install PyGlobalShortcut command, which automatically compiled and installed the libqxt library and the Python wrapper. This worked flawlessly.

Building natively under Windows

However, I hit the wall trying to install PyGlobalShortcut under Windows. The binary distribution for the package is obsolete, meaning I have to compile it myself. I had to install Qt4 + MinGW and tweak $PATH, which was not a problem. Next step is to get SIP, which is unfortunately not provided in a binary form for Py2.7. I got the source code of SIP, but was not able to build it:

sip-4.17 $ python configure.py --platform win32-g++
sip-4.17 $ make

make calls for mingw32-make which immediately returns with an error that MSVCR80.dll could not be found. I googled a bit and it seems that it is a component of MS Visual Studio or something like that, but what does it has to do with MinGW? I was not able to find any kind of official web site that provides this dll or explains how to get it.

Cross-compiling under Linux

I also thought that may be I could cross-compile PyGlobalShortcut on Linux machine using MXE. I did not manage to do this as well. I used this SO answer as a guidance. I've got MXE, cross-compiled Qt4 and checked with wine that it works. Then I included <mxe>/usr/bin and <mxe>/usr/i686-w64-mingw32.static/qt/bin into $PATH and tried to cross-compile SIP for windows. It failed miserably because Makefile called for native linux g++ and not for c++ compiler of MXE:

sip-4.17 $ python configure.py --platform win32-g++
sip-4.17 $ make
make[1]: Entering directory `/home/ximeg/dev/sip-4.17/sipgen'
gcc -c -O2 -w -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -o main.o main.c
gcc -c -O2 -w -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -o transform.o transform.c
gcc -c -O2 -w -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -o gencode.o gencode.c
gcc -c -O2 -w -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -o extracts.o extracts.c
gcc -c -O2 -w -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -o export.o export.c
gcc -c -O2 -w -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -o heap.o heap.c
gcc -c -O2 -w -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -o parser.o parser.c
gcc -c -O2 -w -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -o lexer.o lexer.c
g++ -mthreads -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-subsystem,console -Wl,-s -o sip main.o transform.o gencode.o extracts.o export.o heap.o parser.o lexer.o 
main.o: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status
make[1]: *** [sip] Error 1
make[1]: Leaving directory `/home/ximeg/dev/sip-4.17/sipgen'
make: *** [all] Error 2

So I symlinked compilers and linker under <mxe>/usr/bin, i.e. i686-w64-mingw32.static-g++ to g++ etc. This helped, but now g++ requires Python libraries and headers. It looks for them under /usr/include/python2.7 - but they are compiled for linux and therefore cannot be linked to windows binaries.

sip-4.17 $ make
make[1]: Entering directory `/home/ximeg/dev/sip-4.17/sipgen'
gcc -c -O2 -w -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -o main.o main.c
...
g++ -mthreads -Wl,-enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-subsystem,console -Wl,-s -o sip main.o transform.o gencode.o extracts.o export.o heap.o parser.o lexer.o 
make[1]: Leaving directory `/home/ximeg/dev/sip-4.17/sipgen'
make[1]: Entering directory `/home/ximeg/dev/sip-4.17/siplib'
gcc -c -O2 -w -DNDEBUG -DUNICODE -DQT_LARGEFILE_SUPPORT -I. -I/usr/include/python2.7 -o siplib.o siplib.c
In file included from /usr/include/python2.7/Python.h:8:0,
                 from siplib.c:20:
/usr/include/python2.7/pyconfig.h:78:3: error: #error unknown multiarch location for pyconfig.h
 # error unknown multiarch location for pyconfig.h
   ^
In file included from /usr/include/python2.7/pyport.h:4:0,
                 from /usr/include/python2.7/Python.h:58,
                 from siplib.c:20:
/usr/include/python2.7/pyconfig.h:78:3: error: #error unknown multiarch location for pyconfig.h
 # error unknown multiarch location for pyconfig.h
   ^
In file included from /usr/include/python2.7/pymath.h:4:0,
                 from /usr/include/python2.7/Python.h:77,
                 from siplib.c:20:
/usr/include/python2.7/pyconfig.h:78:3: error: #error unknown multiarch location for pyconfig.h
 # error unknown multiarch location for pyconfig.h
   ^
siplib.c: In function 'wrapInstance':
siplib.c:1342:27: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'addr'
     unsigned PY_LONG_LONG addr;
                           ^
siplib.c:1342:27: error: 'addr' undeclared (first use in this function)
siplib.c:1342:27: note: each undeclared identifier is reported only once for each function it appears in
siplib.c: In function 'parsePass1':
siplib.c:4488:9: error: expected ';' before 'case'
         case 'c':
         ^
siplib.c:4526:9: error: expected ';' before 'case'
         case 'b':
         ^
make[1]: *** [siplib.o] Error 1
make[1]: Leaving directory `/home/ximeg/dev/sip-4.17/siplib'
make: *** [all] Error 2

It seems that I need a Windows build of Python to compile this stuff, placed under <mxe root>, but... Come on, now it's getting way too complicated. I'm pretty sure that I am missing something simple here. Unfortunately I don't have much experience in compiling for Windows and would appreciate any help.

Other options for shortcuts?

I do not mind to rewrite my Python program and use any other cross-platform library to catch global shorcuts, but I did not found any other except PyGlobalShortcut.

来源:https://stackoverflow.com/questions/36551756/build-sip-and-pyglobalshortcut-for-windows

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