微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Clion,macOSMatplotlib:M1 MacBook、ARM64

如何解决Clion,macOSMatplotlib:M1 MacBook、ARM64

我正在尝试使用 Clion 使 Matplotlib 在 macOS 上的 C++ 中工作,因为我需要绘制 2D 图形。但是,在解决了为标头设置路径的一些问题后:Python.harrayobject.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 举报,一经查实,本站将立刻删除。