mardi 31 mars 2015

Running own boost-python module under Windows

I want to create my own python libs with boost python under windows. I tried the same under linux and it works properly.


At first all seems to work good, untill i start the python script "pytest.py":



import sys
sys.path.append("C:\\Users\\Philipp\\Desktop\\Projects\\Project\\build")
print("Python Test")
import libMyBoostModule


Then the error occurs:



C:\Users\Philipp\Desktop\Projects\Project\build>pytest.py
Python Test
Traceback (most recent call last):
File "C:\Users\Philipp\Desktop\Projects\Project\build\pytest.py", line 4, in <module> import libMyBoostModule
ImportError: DLL load failed: The specified module could not be found.


What have I done or tried:


I have build boost with many different options and combinations of them. After b2 toolset=gcc --build-type=complete stage i tried the options variant=release,debug link=static,shared runtime-link=shared python-debugging=off threading=single,multi address-model=32 architecture=x86 and target-os=windows and bevor every build I deleted the bin.v2 folder on the boost root directory and the stage\lib folder and execute the commands b2 --clean-all --toolset=gcc and bootstrap.bat mingw.


After the build of the boost libs I generate the MakeFiles. A snipped of them:



# build library
#ADD_LIBRARY (MyBoostModule STATIC py.cpp)
ADD_LIBRARY (MyBoostModule SHARED py.cpp)
#ADD_LIBRARY (MyBoostModule MODULE py.cpp)
set_target_properties(MyBoostModule PROPERTIES SUFFIX ".pyd")
target_link_libraries(MyBoostModule ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} )


Here you can see, I tried static, shared and module for the boost module. All needed directories can be found and after creating the MakeFiles I can build the project. My C-Code is:



using namespace boost::python;
using namespace std;

BOOST_PYTHON_MODULE(libMyBoostModule)
{
cout << "BP_MESA C++ Modul initialisiert" << endl;
}


All I want to do is, that if I import the module the message should occur on the console. Under linux this code and the python script works fine. The module which I want to import in the python script must have the same name as the module name given in the C-Code. Under these circumstances, the modulename in the makefile has no foregoing "lib". I tried boost and python x86 and x64 in same and different combination. If I change the keyword in the MakeFile from SHARED to STATIC, the error changes to ImportError: DLL load failed: %1 is not a valid Win32 application. I have found some posts about this and the other error but none of them helped me.


What have i done wrong?


Aucun commentaire:

Enregistrer un commentaire