Opened 5 years ago
#13062 new Bugs
LNK2019 Unresolved External Symbol in VS2015 when using Boost python3 and numpy3 libraries on Windows
Reported by: | Owned by: | Ralf W. Grosse-Kunstleve | |
---|---|---|---|
Milestone: | To Be Determined | Component: | python USE GITHUB |
Version: | Boost 1.64.0 | Severity: | Showstopper |
Keywords: | python3 numpy3 | Cc: |
Description
I am getting linker errors when trying to use the numpy3 library on Windows:
test_boost_python.obj : error LNK2019: unresolved external symbol "class boost::python::numpy::dtype __cdecl boost::python::numpy::detail::get_float_dtype<32>(void)" (??$get_float_dtype@$0CA@@detail@numpy@python@boost@@YA?AVdtype@123@XZ) referenced in function "public: static class boost::python::numpy::dtype __cdecl boost::python::numpy::detail::builtin_dtype<float,0>::get(void)" (?get@?$builtin_dtype@M$0A@@detail@numpy@python@boost@@SA?AVdtype@345@XZ)
Small test program to reproduce:
#include <boost/python.hpp> #include <boost/python/numpy.hpp> namespace bp = boost::python; namespace np = boost::python::numpy; np::ndarray test_make_zeros(int rows, int cols) { return np::zeros(bp::make_tuple(rows, cols), np::dtype::get_builtin<float>()); } BOOST_PYTHON_MODULE(test_boost_numpy) { np::initialize(); bp::def("test_make_zeros", test_make_zeros); }
I have downloaded and built Boost 1.64 on Windows by using the following command:
b2 --build-type=complete address-model=64 toolset=msvc stage
I added a user-config.jam file in my home directory to tell Boost where to find Python 3:
using python : 3.6 : c:\\anaconda3\\python ;
I am using the following CMakeLists.txt file:
cmake_minimum_required(VERSION 3.8) project(test_boost_python) set(BOOST_ROOT "C:/Boost-1.64") SET(Boost_ADDITIONAL_VERSIONS 1.64) find_package(PythonLibs 3.6 REQUIRED) include_directories(${PYTHON_INCLUDE_DIRS}) find_package(Boost REQUIRED COMPONENTS python3 numpy3) include_directories(${Boost_INCLUDE_DIRS}) link_directories(${Boost_LIBRARY_DIRS}) add_library(test_boost_python SHARED test_boost_python.cpp) set_target_properties(test_boost_python PROPERTIES PREFIX "" SUFFIX ".pyd") set_target_properties(test_boost_python PROPERTIES DEFINE_SYMBOL "BOOST_ALL_NO_LIB") target_link_libraries(test_boost_python ${PYTHON_LIBRARIES} ${Boost_LIBRARIES})
My boost::python library is given the name boost_python3-vc140-mt-1_64.lib and boost::numpy ends up as boost_numpy3-vc140-mt-1_64.lib when linking against Python 3.6.
I had to turn on BOOST_ALL_NO_LIB. If not, the compiler looks for boost_python-vc140-mt-1_64.lib boost_numpy-vc140-mt-1_64.lib (which is under the wrong name, with a missing number 3 after the library names; possibly also a bug on Windows?)
See also https://stackoverflow.com/questions/44072440/lnk2019-unresolved-external-symbol-in-vs2015-when-using-boost-python3-and-numpy3 for more information