From oystein.skotheim at zividlabs.com Mon May 22 15:05:41 2017 From: oystein.skotheim at zividlabs.com (=?iso-8859-1?Q?=D8ystein_Skotheim?=) Date: Mon, 22 May 2017 19:05:41 +0000 Subject: [C++-sig] LNK2019 Unresolved External Symbol in VS2015 when using Boost python3 and numpy3 libraries on Windows Message-ID: 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 then trying to compile a small test project using boost::python and boost::numpy: #include #include 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()); } BOOST_PYTHON_MODULE(test_boost_python) { np::initialize(); bp::def("test_make_zeros", test_make_zeros); } 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 - Is this a bug on Windows?) For my test project, I now get the following linking error: 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 at numpy@python at boost@@YA?AVdtype at 123@XZ) referenced in function "public: static class boost::python::numpy::dtype __cdecl boost::python::numpy::detail::builtin_dtype::get(void)" (?get@?$builtin_dtype at M$0A@@detail at numpy@python at boost@@SA?AVdtype at 345@XZ) What may be the reason for this missing symbol and how should I go about to fix it? -?ystein From hzhou3 at clemson.edu Thu May 25 00:54:16 2017 From: hzhou3 at clemson.edu (Heng Zhou) Date: Thu, 25 May 2017 00:54:16 -0400 Subject: [C++-sig] Cannot import the Hello World module of Boost.Python's QuickStart in python Message-ID: I followed the steps in the QuickStart of Boost.Python here: https://urldefense.proofpoint.com/v2/url?u=http-3A__www.boost.org_doc_libs_1-5F49-5F0_libs_python_doc_tutorial_doc_html_index.html&d=DwIBaQ&c=Ngd-ta5yRYsqeUsEDgxhcqsYYY1Xs5ogLxWPA_2Wlc4&r=jSyKml46sQcyHEvdXhVDNwoCqN0MBfWgTmJFqTljZKM&m=6Z-RP-Mjs781YKE08gvO6owK6zMqGXD7ZRueaJHfUNo&s=2-beQ7RazSZIfAiaWI9QGvRv_EumlzP0E6iD2Qfmntg&e= . I can successfully compile, link and get the output dll file, but I always got and error: Traceback (most recent call last): File "", line 1, in ImportError: No module named hello_ext when trying to import it in python. This is my environment: - Windows 7 Enterprise SP1 64 bit, I am the Administrator and run cmd as Administrator. - Python 2.7.13 64 bit - Visual Studio 2015 (v14.0) Update 3 - In VS2015, the project name is ConsoleApplication1, so the output is ConsoleApplication1.dll. - I built the simple sample code under x64 configuration in VS2015 and I verified with dumpbin that the output ConsoleApplication1.dll is really 64 bit. I tried the following but got the same error: - I added the search path to the ConsoleApplication1.dll into sys.path - I changed the name of ConsoleApplication1.dll to hello_ext.dll The QuickStart says "The resulting DLL is now visible to Python." but that magic does not take place on my machine. Could you please tell me what I had missed or, if I built the DLL properly, how to import it in python command line? Thanks a lot. -------------- next part -------------- An HTML attachment was scrubbed... URL: From hzhou3 at clemson.edu Fri May 26 01:32:46 2017 From: hzhou3 at clemson.edu (Heng Zhou) Date: Fri, 26 May 2017 01:32:46 -0400 Subject: [C++-sig] Cannot import the Hello World module of Boost.Python's QuickStart in python In-Reply-To: References: Message-ID: I solved the problem myself. This is a link to my answer: https://urldefense.proofpoint.com/v2/url?u=https-3A__stackoverflow.com_questions_44161857_the-2Ddll-2Dcreated-2Dby-2Dboost-2Dpython-2Dcannot-2Dbe-2Dimported-2Dfollowing-2Dboost-2Dpythons-2Dqui_44194094-2344194094&d=DwIBaQ&c=Ngd-ta5yRYsqeUsEDgxhcqsYYY1Xs5ogLxWPA_2Wlc4&r=jSyKml46sQcyHEvdXhVDNwoCqN0MBfWgTmJFqTljZKM&m=Z6BHCcdSSCk4Tyk1aODuxJJLvF5j7M6QqGMajnzntSs&s=1iKwggA27bECIO0iVuLFA4Zz40g5EQ38MrwLBqKfBjY&e= On Thu, May 25, 2017 at 12:54 AM, Heng Zhou wrote: > I followed the steps in the QuickStart of Boost.Python here: > https://urldefense.proofpoint.com/v2/url?u=http-3A__www.boost.org_doc_libs_1-5F49-5F0_libs_python_doc_&d=DwIBaQ&c=Ngd-ta5yRYsqeUsEDgxhcqsYYY1Xs5ogLxWPA_2Wlc4&r=jSyKml46sQcyHEvdXhVDNwoCqN0MBfWgTmJFqTljZKM&m=Z6BHCcdSSCk4Tyk1aODuxJJLvF5j7M6QqGMajnzntSs&s=B7c9mrc4EPId10XO2UsWu_OZHNf3tA6rtPRvqJ2f_dE&e= > tutorial/doc/html/index.html. I can successfully compile, link and get > the output dll file, but I always got and error: > > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named hello_ext > > when trying to import it in python. This is my environment: > > - Windows 7 Enterprise SP1 64 bit, I am the Administrator and run cmd as > Administrator. > - Python 2.7.13 64 bit > - Visual Studio 2015 (v14.0) Update 3 > - In VS2015, the project name is ConsoleApplication1, so the output is > ConsoleApplication1.dll. > - I built the simple sample code under x64 configuration in VS2015 and I > verified with dumpbin that the output ConsoleApplication1.dll is really 64 > bit. > > I tried the following but got the same error: > - I added the search path to the ConsoleApplication1.dll into sys.path > - I changed the name of ConsoleApplication1.dll to hello_ext.dll > > The QuickStart says "The resulting DLL is now visible to Python." but that > magic does not take place on my machine. Could you please tell me what I > had missed or, if I built the DLL properly, how to import it in python > command line? Thanks a lot. > -------------- next part -------------- An HTML attachment was scrubbed... URL: