Boost C++ Libraries: Ticket #12921: Linker Error with numpy in boost/python https://svn.boost.org/trac10/ticket/12921 <p> I am the author of the attached (and solved) stackoverflow question: <a class="ext-link" href="http://stackoverflow.com/questions/42899376/lnk2001-error-when-using-boostnumpy/42936160#42936160"><span class="icon">​</span>http://stackoverflow.com/questions/42899376/lnk2001-error-when-using-boostnumpy/42936160#42936160</a> </p> <p> My question is, is the described behavior a bug? </p> <p> Let me start with the answer: </p> <p> Import the Boost\python numpy package like: </p> <p> #define BOOST_LIB_NAME "boost_numpy" </p> <p> #include &lt;boost/python.hpp&gt; </p> <p> The Problem description (copy from Stackoverflow): </p> <p> I am trying to call a C++ .dll from Python and return a numpy array. I am using </p> <p> Anaconda 2.7 x64 Visual Studio 2013 update 5 boost 1.63.0 prebuileded for lib64-msvc-12.0 I managed to compile this simple example frome here and run it in Python: </p> <p> #include "stdafx.h" #define BOOST_PYTHON_STATIC_LIB #include &lt;boost/python.hpp&gt; </p> <p> char const* greet() { </p> <blockquote> <p> return "hello, world"; </p> </blockquote> <p> } </p> <p> BOOST_PYTHON_MODULE(test) { </p> <blockquote> <p> using namespace boost::python; def("greet", greet); </p> </blockquote> <p> } I am unsure about the #define BOOST_PYTHON_STATIC_LIB but without it python could not open the pyd file. I suspected that python could not resolve the references to MSVCR120.dll in the dynamic build, but I am just guessing. </p> <p> Next step was to include &lt;boost/python/numpy.hpp&gt; and follow this instuctions and start with just creating a numpy::ndarray. Yes, I am aware that void is in contradiction to the intention of getting values, I just wanted to keep things as simple as possible. </p> <p> #include &lt;boost/python/numpy.hpp&gt; namespace p = boost::python; namespace np = boost::python::numpy; </p> <p> void getNPArray() { </p> <blockquote> <p> Py_Initialize(); np::initialize(); p::object tu = p::make_tuple('a', 'b', 'c'); np::ndarray const example_tuple = np::array(tu); return; </p> </blockquote> <p> } The import and namespace declarations compile without error. At next step I encountered the linker error. While Py_Initialize() worked fine, the np::initialize() causes the linker to throw </p> <p> error LNK2001: unresolved external symbol "void <span class="underline">cdecl boost::python::numpy::initialize(bool)" (?initialize@numpy@python@boost@@YAX_N@Z) And np::ndarray const example_tuple = np::array(tu) causes a </span></p> <p> error LNK2001: unresolved external symbol "class boost::python::numpy::ndarray <span class="underline">cdecl boost::python::numpy::array(class boost::python::api::object const &amp;)" (?array@numpy@python@boost@@YA?AVndarray@123@AEBVobject@api@23@@Z) As the linker is perfectly happy with the first example I am toally confused about what is going on here. I also tried to comment out all parts from the first example and just compile the second part witout any change in behaviour. </span></p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12921 Trac 1.4.3 Niko Koester <niko.koester@…> Wed, 22 Mar 2017 15:16:38 GMT <link>https://svn.boost.org/trac10/ticket/12921#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12921#comment:1</guid> <description> <p> [update] I am sorry but I have to revise my statement that the definition #define BOOST_LIB_NAME "boost_numpy" solved the issue. The np::initialize() line was still commented out when I tested it. Actually I only gives an etxtra warning "C4005: 'BOOST_LIB_NAME' : macro redefinition" </p> <p> So the issue is not solved for me. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Sun, 16 Apr 2017 08:46:12 GMT</pubDate> <title>component changed; owner set https://svn.boost.org/trac10/ticket/12921#comment:2 https://svn.boost.org/trac10/ticket/12921#comment:2 <ul> <li><strong>owner</strong> set to <span class="trac-author">Ralf W. Grosse-Kunstleve</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">python USE GITHUB</span> </li> </ul> <p> Please use Github to file Boost.Python issues. </p> Ticket