2

I have problems linking against boost python.

I am using Visual Studio 2017 and compiled the boost 1_64 package with the following command line:

b2 -a toolset=msvc-14.1 --build_type=complete stage variant=debugthreading=multi link=shared runtime-link=shared define=_ITERATOR_DEBUG_LEVEL=0 address-model=64

with this user-config.jam:

using python 
: 3.6                   # Version
: C:\\Python36\\python.exe      # Python Path
: C:\\Python36\\include         # include path
: C:\\Python36\\libs            # lib path(s)
: <define>BOOST_ALL_NO_LIB=1
;

But while building my c++ project with runtime libary: Multi-threaded DLL (/MD) I keep getting this error message:

Error   LNK1104 cannot open file 'boost_python-vc141-mt-gd-1_64.lib'    

but the boost libs I compiled contain the following boost_python files:

boost_python3-vc141-mt-gd-1_64.dll
boost_python3-vc141-mt-gd-1_64.lib

Does someone have experience with boost for python 3? After hours of trying, I can't find a good solution. Btw.: renaming the files to boost_python- (removing the 3) works fine. But I don't think that this is the correct way


VC Project settings:

Add. include directories:

C:\Python36\include;D:\ws\boost_1_64_0\boost_1_64_0;

Add. libary directories:

D:\ws\boost_1_64_0\boost_1_64_0\stage\lib;C:\Python36\libs;

Closed: The autolink feature of boost did not work correctly with python 3. The boost_module_name macro was set to boost_python (missing the 3) and the generated libs contained the 3.

--> Turned auto link off and added the required libs manually.


Solution a) Go to boost/python/detail/config.hpp and change BOOST_LIB_NAMe to boost_python3 instead of boost_python.

or

Solution b) Turn auto Linkage of by defining BOOST_ALL_NO_LIB and then explicitly set boost_python3...lib as linker dependency.

6
  • What are the build commands for your C++ project? Are you use something like distutils.extension? Commented May 24, 2017 at 9:47
  • I'm not using any special extensions or settings. all i did was creating a c++ 32 console aplication project and changed the code generation to DLL. And added the requiered include paths of course Commented May 24, 2017 at 9:48
  • Please provide enough information. How is your C++ code compiled and, in particular, linked? Give the full command. Failing that, we cannot really help you, I'm afraid. Commented May 24, 2017 at 9:51
  • Is there a way to get the command from visual studio ? Commented May 24, 2017 at 9:54
  • I suspect that VS attempts to build a python (version 2), not a python3 module. Commented May 24, 2017 at 9:54

3 Answers 3

1

You provide

boost_python3-vc141-mt-gd-1_64.dll
boost_python3-vc141-mt-gd-1_64.lib

but the error reports missing

boost_python-vc141-mt-gd-1_64.lib

(spot the difference!)

So obviously, your IDE (VS) attempts to build a python, not a python3 extension. I don't know VS, but there must be away to change that somewhere somehow.

Sign up to request clarification or add additional context in comments.

1 Comment

I'Ve noticed the difference, sorry if this was not clear. but i still could not fidn a way to configure this in vs
1

Sorry for coming in late here, just went through the same nonsense myself. Turns out that boost doesn't handle two installs very well (or even a py3.x by itself)

You can definitely solve this by going into <boost/python/detail/config.hpp> and making a quick change. To allow for boost to work with both python 2.x (2.7, presumably) and 3.x, I'd suggest changing:

#define BOOST_LIB_NAME boost_python

to

#if PY_MAJOR_VERSION >=3
  #define BOOST_LIB_NAME boost_python3
#else
  #define BOOST_LIB_NAME boost_python
#endif

Comments

0

I just want to heads up here as this happened to me. Here is the link. It may have been that you included the 2.7 python headers instead of the 3.6. And yea, nothing about it is obvious, it really put me to work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.