compile some code with boost.python by mingw in win7-64bit

后端 未结 2 1366
迷失自我
迷失自我 2021-01-03 13:01

I decided to make my program compatible with windows environment.But I have very little programming experience on windows.There are some errors need help.

Environmen

2条回答
  •  难免孤独
    2021-01-03 13:16

    You got the paths, but you're not linking against the boost and python library:

    -lboost_python -lpython27
    

    Also you're trying to create an executable (that's why you had to add a main() to the example in order to compile it). For python modules, you want to create a shared library, matching the name defined by the BOOST_PYTHON_MODULE(...) macro. The extension of these modules should be .pyd.

    -shared -o hello_ext.pyd
    

    If the linker can't find the boost_python library, check your boost library directory. Depending on your installation, you should have a libboost_python.a or libboost_python-mgw??-mt-1_??.a. If you can't find anything like that, you have to build them first. You should decide if you want to build static or shared libraries. More details here.

    c:\boost_1_52> b2 toolset=gcc --with-python
    

    This will fail if boost can't find your python installation. To configure (usually a non-standard location of) python, edit the user-config.jam. This may be in your %HOMEDRIVE%%HOMEPATH% or boost_1_52_0\tools\build\v2. Locate Python configuration in that file and set the proper paths (if python was installed at the default location, this step shouldn't be required). The syntax is:

    using python : python_version : python_base : python_incl : python_lib ;
    

    For example:

    using python : 2.7 : c:/Python27 : c:/Python27/include : c:/Python27/libs ;
    

    If you choose to build the static boost python library, you may get other errors when linking your program. If that's the case, you have to indicate that you want to link against the static library with:

    -DBOOST_PYTHON_STATIC_LIB
    

    Lastly, the compiler may complain about ::hypot not being declared. To fix that, #include before including the boost/python headers.

提交回复
热议问题