无法构建使用Python的项目

时间:2018-01-20 07:17:14

标签: python c++ visual-studio visual-c++ unresolved-external

我正在尝试在Visual C ++项目中使用https://github.com/lava/matplotlib-cpp 我添加了libs

  

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

但我仍然会收到错误

  

错误LNK2019:未解析的外部符号__imp_PyObject_GetAttrString在函数“private:__cdecl matplotlibcpp :: detail :: _ interpreter :: _ interpreter(void)”中引用(?? 0_interpreter @ detail @matplotlibcpp @@ AEAA @XZ)   错误LNK2019:未解析的外部符号__imp__Py_NegativeRefcount在函数“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'$ @分配器@ d @@ 2 2 @@ Z)   错误LNK2019:未解析的外部符号__imp__Py_Dealloc在函数“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'$ @分配器@ d @@ 2 2 @@ Z)   ...

我还需要添加什么?

现在它可以构建。我不知道发生了什么。现在我在这个地方遇到运行时错误

    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()给出了

  

ImportError:numpy.core.multiarray无法导入

2 个答案:

答案 0 :(得分:0)

可能您的系统中未安装numpy库。选择安装python解释器的python环境,然后从Overview向下滚动到pip。键入" numpy"并安装它。另一个选择是卸载python并安装Anaconda,它默认包含numpy库。

答案 1 :(得分:0)

我在使用调试模式时遇到了类似的问题。

解决此问题的一种方法是在使用python.exe -m pip install matplotlib安装numpy并使用库python36.lib后,在发布模式下构建它。