1

I have built the Boost 1.64.0 Python libraries, using MS Visual Studio Professional 2017 and 32-bit Python 3.4. Now, when I write an application against the resulting library, I'm getting the following link error:

LINK : fatal error LNK1104: cannot open file 'libboost_python-vc141-mt-1_64.lib'

I have looked in the stage/lib directory, and indeed, the library is named libboost_python3-vc141-mt-1_64.lib (note the 3 in the name). I'm assuming the 3 is referencing the fact that the Boost Python library was generated using Python 3. Why is there a naming inconsistency between the library that was built, and the library that my project is attempting to import? Is it simply a missing macro definition in my project configuration?

Jeff G
  • 4,470
  • 2
  • 41
  • 76
  • Some people who have python2 and python3 on their system will name python3 pyhon3 instead of python. I imagine that this could be the root of your problem but I really don't know. – kpie Aug 07 '17 at 01:16
  • In `VCC++ Directories -> Include Directories`, add your `c:\....\Python36_3\include` path. I'm almost sure it will make things work. – lakeweb Aug 07 '17 at 16:15

1 Answers1

1

In MSVC builds, the boost headers use MSVC #pragma comments to autolink to the boost libraries, see boost/config/auto_link.hpp.

In addition to including auto_link.hpp, the boost/python/detail/config.hpp file contains:

// Set the name of our library, this will get undef'ed by auto_link.hpp
// once it's done with it:
//
#define BOOST_LIB_NAME boost_python

Which is why MSVC is trying to autolink to libboost_python-vc141-mt-1_64.lib.

Clearly your boost build has built libboost_python3-vc141-mt-1_64.lib instead. As suggested by @kpie, your boost build may have named the python library file depending upon whether it's built for python 3 or python 2...

The answers to this question describes how to build boost for python 3. It may answer your macro question regarding the build.

To fix the issue, you could disable autolinking, or simply rename the library file to remove the "3".

kenba
  • 4,303
  • 1
  • 23
  • 40
  • After having read through the questions and answers you linked, I'm still a little confused as to the correct path forward. I understand your suggestion to disable autolinking; does that imply that there is no way to use auto-linking with Boost Python 3? When you suggest to rename the file, is that a configuration option that is set in user-config.jam, or are you suggesting I manually rename the file in Windows Explorer? I find it difficult to believe that the Boost Python designers would force the generated library name to be different than the name being auto-linked, with no way to fix it. – Jeff G Aug 07 '17 at 17:01
  • Based on some of the questions you linked, I have tried to define the `PY_MAJOR_VERSION=3` macro, which didn't have any effect. I have also tried to add the Python 3 include directory as the first entry in my Additional Include Directories setting, which also didn't work. I may try to remove the explicit version from my user-config.jam file, and see if that generates the library without the "3" in the name. – Jeff G Aug 07 '17 at 17:03
  • My boost builds contain *both* `python` and `python3` libraries, I think that your user-config.jam file may be causing the problem. `MSVC boost` pre-built binaries are available [here](https://sourceforge.net/projects/boost/files/boost-binaries/1.64.0/) they also contain both. I recommend that you use simply one of them. – kenba Aug 08 '17 at 07:19
  • Interesting... my user-config.jam file is in *tools\build\src*, and contains only two lines: `import toolset : using ;`, and `using python : 3.4 : C:\\Python34 ;`. To build Boost, I am running `bootstrap`, followed by `.\b2 address-model=32 stage`. Is any of this appreciably different than how you are building Boost? Perhaps *stage* isn't the correct target. – Jeff G Aug 08 '17 at 12:31
  • @Jeff G I'm pretty sure that `stage` is the correct target! I build `boost` using the instructions [here](https://stackoverflow.com/questions/35217511/boost-1-60-0-zip-installation-in-windows/35223257#35223257), although for `MSVC 17` it should now use `toolset=msvc-14.1` – kenba Aug 08 '17 at 16:41
  • Thanks for the link... I followed those instructions, and still didn't get a boost python library without the *3* in the name. Ultimately, I just created two symbolic links (using the `mklink` command) without the *3* in their name, to point to the boost build output. – Jeff G Aug 09 '17 at 22:02
  • @Jeff G I think that the symbolic links are a far better solution than my renaming suggestion. I'm glad to hear that it works. – kenba Aug 10 '17 at 06:54