简体   繁体   中英

Boost.Python Quickstart Linker Errors

I'm just trying to follow the instructions here to get the Quickstart example working. I am on Windows 7 and trying to use MSVC. I have Python 2.7 installed.

What I have done:

  • Download boost_1_57_0.zip and extract to C:\\boost_1_57_0 .
  • From command prompt in C:\\boost_1_57_0 , run:

     bootstrap 

    then:

     .\\b2 

    as per the instructions under 5.1 here . After this I have a message saying "The Boost C++ Libraries were successfully built!".

  • Add C:\\boost_1_57_0 to my path. The instructions don't say to do this, but since they want me to invoke bjam, and that's where it lives, I assume I need to do this.
  • Modify C:\\boost_1_57_0\\libs\\python\\example\\quickstart\\boost-build.jam so that the path is boost-build ../../../../tools/build/src ; and not boost-build ../../../../tools/build/v2 ; . This is as per the instructions here since the original path is wrong and if you don't do this the bjam invocation fails.
  • CD into C:\\boost_1_57_0\\libs\\python\\example\\quickstart and run:

     bjam toolset=msvc --verbose-test test 

The output I get is firstly:

...patience...
...patience...
...found 1926 targets...
...updating 55 targets...
common.mkdir bin
common.mkdir bin\test_ext.test
common.mkdir bin\test_ext.test\msvc-12.0
common.mkdir bin\test_ext.test\msvc-12.0\debug
common.mkdir bin\test_ext.test\msvc-12.0\debug\threading-multi
common.mkdir bin\msvc-12.0
common.mkdir bin\msvc-12.0\debug
common.mkdir bin\msvc-12.0\debug\threading-multi
compile-c-c++ bin\msvc-12.0\debug\threading-multi\extending.obj
extending.cpp
c:\python27\include\pymath.h(22) : warning C4273: 'round' : inconsistent dll linkage
    C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\math.h(516) : see previous definition of 'round'
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\xtgmath.h(190) : warning C4273: '_hypot' : inconsistent dll linkage

followed by a long list of other header file entries, each complaining about inconsistent dll linkage, and then at the end a bunch of errors, highlights of which include:

LINK : fatal error LNK1207: incompatible PDB format in 'C:\boost_1_57_0\libs\python\example\quickstart\bin\msvc-12.0\debug\threading-multi\extending.pdb'; delete and rebuild

...failed msvc.link.dll bin\msvc-12.0\debug\threading-multi\extending.pyd bin\msvc-12.0\debug\threading-multi\extending.pdb...
...removing bin\msvc-12.0\debug\threading-multi\extending.pdb

LINK : warning LNK4001: no object files specified; libraries used
LINK : error LNK2001: unresolved external symbol _mainCRTStartup
bin\test_embed.test\msvc-12.0\debug\threading-multi\test_embed.exe : fatal error LNK1120: 1 unresolved externals

...failed msvc.link bin\test_embed.test\msvc-12.0\debug\threading-multi\test_embed.exe bin\test_embed.test\msvc-12.0\debug\threading-multi\test_embed.pdb...
...removing bin\test_embed.test\msvc-12.0\debug\threading-multi\test_embed.pdb
...skipped <pbin\test_embed.test\msvc-12.0\debug\threading-multi>test_embed.run for lack of <pbin\test_embed.test\msvc-12.0\debug\threading-multi>test_embed.exe...
...failed updating 4 targets...

Any ideas?

The problem is still present with 1.59. I've managed to get Boost.Build working again by editing the file:

D:\boost\boost_1_59_0\tools\build\src\tools\msvc.jam

I made two changes:

  1. Change this (lines #1351-1355):

      generators.register [ new msvc-linking-generator msvc.link.dll : OBJ SEARCHED_LIB STATIC_LIB IMPORT_LIB : SHARED_LIB IMPORT_LIB : <toolset>msvc <suppress-import-lib>false ] ; generators.register [ new msvc-linking-generator msvc.link.dll : OBJ SEARCHED_LIB STATIC_LIB IMPORT_LIB : SHARED_LIB : <toolset>msvc <suppress-import-lib>true ] ; 

    to:

      generators.register [ new msvc-linking-generator msvc.link.dll : OBJ SEARCHED_LIB STATIC_LIB IMPORT_LIB : SHARED_LIB IMPORT_LIB : <toolset>msvc ] ; 
  2. Remove this line (#1472):

      toolset.flags msvc.link.dll LINKFLAGS <suppress-import-lib>true : /NOENTRY ; 

I've tested this on Win7 with VS2012 and Python 2.7.

I also saw that incompatible PDB format issue, but only with 1.57, which (since the Boost.Python source is the same for 1.57 and 1.55 and I can get it working on 1.55) I'm guessing is somehow related to the changes in the boost::build path.

I've documented what I had to do to get it working with 1.55, maybe that will be some help.

Madness I tell you.

Anyway, I finally succeeded in building the quickstart example on boost_1_68_0. A quick guidethrough:

  • (On windows, visual studio 2017 and SDK installed, python 3.5 installed)
  • Download and extract it in like C:\\boost_1_68_0
  • Run bootstrap.bat
  • Build the boost-python libraries:

C:\\boost_1_68_0>.\\b2 --with-python -j4

  • Go to C:\\boost_1_68_0\\libs\\python\\example, and fix the Jamroot to find your header files

  project : requirements <include>C:\\\\boost_1_68_0 <library>boost_python 

  • Fix the tools\\build\\src\\tools\\msvc.jam file in the way Ralph in this post commented
  • As described here , patch embedding.cpp and extending.cpp by adding "#define BOOST_PYTHON_STATIC_LIB" as the first line everywhere
  • Copy the built python-boost libs (from C:\\boost_1_68_0\\stage\\lib) to the quickstart folder
  • Finally build it

C:\\boost_1_68_0\\libs\\python\\example\\quickstart>..\\..\\..\\..\\b2.exe -j4

Again, this is -crazy- complex. All the other stuff builds just fine, but the python linkage is really broken. Anyway, in case anyone tries, hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM