You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows环境下编译包含matplotlibcpp.h的C++代码报错的解决方案咨询

Windows环境下编译包含matplotlibcpp.h的C++代码报错的解决方案咨询

我在Windows上折腾C++调用matplotlib绘图时卡壳了,想请教大家怎么解决这个问题,具体情况如下:

环境与准备工作

  • 已经安装Python 3.8.18
  • 从仓库下载了matplotlibcpp.h文件,将其放在了C++代码的同一目录下
  • 尝试用vcpkg安装matplotlib失败,转而手动用g++编译代码

我的C++代码

#include "matplotlibcpp.h"

int main(int argc, char const *argv[])
{
    matplotlibcpp::plot({1,3,2,4});
    matplotlibcpp::show();
    return 0;
}

使用的编译命令

g++ main.cpp -o out -I C:\python\include -I C:\python\Lib\site-packages\numpy\core\include\numpy

编译报错信息

编译时先出现了几处关于Python API弃用的警告(比如Py_SetProgramName和PySys_SetArgv已被标记为deprecated),之后弹出大量未定义引用错误,核心错误片段如下:

c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\DEHGHA~2.KCR\AppData\Local\Temp\ccTTMRIo.o:main.cpp:(.text+0x35): undefined reference to `_imp__PyImport_ImportModule'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\DEHGHA~2.KCR\AppData\Local\Temp\ccTTMRIo.o:main.cpp:(.text+0x64): undefined reference to `_imp__PyObject_GetAttrString'
...
collect2.exe: error: ld returned 1 exit status

想请教各位,在Windows环境下怎么解决这个编译报错问题?

备注:内容来源于stack exchange,提问作者Hossein

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.20 06:14:33