1
votes

I am trying to use https://github.com/lava/matplotlib-cpp in my Visual C++ project.
I added libs

Python36-32\libs\python36_d.lib
Python36-32\libs\python3_d.lib

But I still get errors

error LNK2019: unresolved external symbol __imp_PyObject_GetAttrString referenced in function "private: __cdecl matplotlibcpp::detail::_interpreter::_interpreter(void)" (??0_interpreter@detail@matplotlibcpp@@AEAA@XZ) error LNK2019: unresolved external symbol __imp__Py_NegativeRefcount referenced in function "bool __cdecl matplotlibcpp::plot(class std::vector > const &,class std::vector > const &,class std::basic_string,class std::allocator > const &)" (??$plot@NN@matplotlibcpp@@YA_NAEBV?$vector@NV?$allocator@N@std@@@std@@0AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z) error LNK2019: unresolved external symbol __imp__Py_Dealloc referenced in function "bool __cdecl matplotlibcpp::plot(class std::vector > const &,class std::vector > const &,class std::basic_string,class std::allocator > const &)" (??$plot@NN@matplotlibcpp@@YA_NAEBV?$vector@NV?$allocator@N@std@@@std@@0AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z) ...

What else do I need to add?


Now it can be built. I don't know what happened. And now I get runtime error in this place

    PyObject* matplotlibname = PyString_FromString("matplotlib");
    PyObject* pyplotname = PyString_FromString("matplotlib.pyplot");
    PyObject* pylabname  = PyString_FromString("pylab");
    if (!pyplotname || !pylabname || !matplotlibname) {
        throw std::runtime_error("couldnt create string");
    }

PyErr_Print() gives

ImportError: numpy.core.multiarray failed to import

2

2 Answers

0
votes

Maybe the numpy library is not installed in your system. Select the python environment that your python interpreter is installed and scroll down from Overview to pip. Type "numpy" and install it. The other option you have is to uninstall python and install Anaconda, which contains by default the numpy library.

0
votes

I encountered a similar problem using Debug mode.

One way to overcome this is to build it in Release mode, after installing numpy with python.exe -m pip install matplotlib, and using the library python36.lib.