问题描述
我正在尝试使用 Clion 使 Matplotlib 在 macOS 上的 C++ 中工作,因为我需要绘制 2D 图形。但是,在解决了为标头设置路径的一些问题后:Python.h
和 arrayobject.h
,我无法解决以下错误:Undefined symbols for architecture arm64
,即
Undefined symbols for architecture arm64:
"_PyCObject_AsVoidPtr",referenced from:
_import_array() in main.cpp.o
"_PyCObject_Type",referenced from:
_import_array() in main.cpp.o
"_PyErr_Format",referenced from:
_import_array() in main.cpp.o
"_PyErr_Print",referenced from:
matplotlibcpp::detail::_interpreter::_interpreter() in main.cpp.o
matplotlibcpp::detail::_interpreter::import_numpy() in main.cpp.o
"_PyErr_SetString",referenced from:
matplotlibcpp::detail::_interpreter::import_numpy() in main.cpp.o
_import_array() in main.cpp.o
"_PyExc_AttributeError",referenced from:
_import_array() in main.cpp.o
"_PyExc_ImportError",referenced from:
matplotlibcpp::detail::_interpreter::import_numpy() in main.cpp.o
_import_array() in main.cpp.o
"_PyExc_RuntimeError",referenced from:
_import_array() in main.cpp.o
"_PyFunction_Type",referenced from:
matplotlibcpp::detail::_interpreter::_interpreter() in main.cpp.o
"_PyImport_Import",referenced from:
matplotlibcpp::detail::_interpreter::_interpreter() in main.cpp.o
"_PyImport_ImportModule",referenced from:
_import_array() in main.cpp.o
"_PyObject_CallMethod",referenced from:
matplotlibcpp::detail::_interpreter::_interpreter() in main.cpp.o
"_PyObject_CallObject",referenced from:
matplotlibcpp::colorbar() in main.cpp.o
"_PyObject_GetAttrString",referenced from:
matplotlibcpp::detail::_interpreter::_interpreter() in main.cpp.o
_import_array() in main.cpp.o
"_PyString_FromString",referenced from:
matplotlibcpp::detail::_interpreter::_interpreter() in main.cpp.o
"_PyTuple_New",referenced from:
matplotlibcpp::detail::_interpreter::_interpreter() in main.cpp.o
"_Py_Finalize",referenced from:
matplotlibcpp::detail::_interpreter::~_interpreter() in main.cpp.o
"_Py_Initialize",referenced from:
matplotlibcpp::detail::_interpreter::_interpreter() in main.cpp.o
"_Py_SetProgramName",referenced from:
matplotlibcpp::detail::_interpreter::_interpreter() in main.cpp.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command Failed with exit code 1 (use -v to see invocation)
make[3]: *** [untitled] Error 1
make[2]: *** [CMakeFiles/untitled.dir/all] Error 2
make[1]: *** [CMakeFiles/untitled.dir/rule] Error 2
make: *** [untitled] Error 2
我的主文件(我从 Matplotlib 文件中获取的示例):
#include <iostream>
#include "matplotlibcpp.h"
#include <vector>
namespace plt = matplotlibcpp;
int main() {
std::vector<double> y = {1,3,2,4};
plt::plot(y);
return 0;
}
Matplotlib.cpp:
#pragma once
#include <algorithm>
#include <array>
#include <cstdint> // <cstdint> requires c++11 support
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <stdexcept>
#include <vector>
#include <sstream>
#include </System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h>
#ifndef WITHOUT_NUMPY
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#include </System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/include/numpy/arrayobject.h>
#endif // WITHOUT_NUMPY
请注意:我的 C++ 程序的主要目的是解决我已经完成的“一些”PDE 系统,我知道它有效(我检查了绘制的曲线趋势(收敛等)和 MS Excel 中的值),但是,在 MS Excel 中绘制值非常慢,因此会适得其反。
我没有用 C++ 绘制二维图形的经验。因此,如果有任何更简单的方法(库等)在 C++(macOS、Clion、amr64 M1)中绘制 2D 图,我不需要坚持使用 Matplotlib。
谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)