Reputation: 591
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.
Upvotes: 2
Views: 5706
Reputation: 895
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
Upvotes: 1
Reputation: 1939
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.
Upvotes: 0
Reputation: 45414
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.
Upvotes: 1