Python hangs when I try to import a C ++ shared library into python 2.5 for Windows, and I don't know why.
On Linux, everything works fine. We can compile all our C ++ code, generate swig shell classes. They are compiled and can be imported and used in python 2.5 or 2.6. Now we are trying to port the code to Windows using Cygwin.
We can compile each of the C ++ libraries for shared DLLs using -mno-cygwin, which removes the dependency on cygwin1.dll. Essentially, this means that gcc's goal is MinGW instead of Cygwin, allowing executable binaries to run on Windows without any dependency on Cygwin. Moreover, each of these shared libraries can be linked to C ++ binaries and work successfully.
Once this is done, we used swig to create wrappers for each of the shared libraries. These wrappers are generated, compiled and linked without problems.
The next step was to import the generated python shell into python. We can import everything except our two libraries. For two that don't work, when we try to import .py or .pyd files into Windows python (version compiled with Visual C ++), python hangs up. We cannot kill python with ctrl + c or ctrl + d, the only way is to kill it through the task manager. If we attach gdb to the python process and print the stack trace, we basically get garbage, nothing useful.
Then we tried to do ifdef'ing blocks of code in * .i files and recreate swig wrappers. This process at least allowed me to import the libraries into Windows python, but the problem is that we had to comment on too many functions needed to run the software. In general, there were three types of functions that needed to be commented on: static functions, virtual const functions, and regular public functions that were NOT declared as const. It is also reproducible, if we uncomment any of these functions, then the import freezes again.
hello, swig python. . . , . .
, , , .
Linux gcc 3 4 python 2.5 2.6.
Windows , : gcc 3.4.4 swig 1.39 ( Windows swig.org) python 2.5.4 ( Windows /libs python.org)
, hello ( , - -I, -L -l)
swig -++ -python -o test_wrap.cc test.i
gcc -c -mno-cygwin test.cc
gcc -c -mno-cygwin test_wrap.cc -I/usr/python25/include
dlltool --export-all --output-def _test.def test.o
gcc -mno-cygwin -shared -s test_wrap.o test.o -L/usr/python25/libs -lpython25 -lstd++ -o _TestModule.pyd
,
AJ