I'm trying to get Matplotlib working in C++ on macOS using Clion as I need to plot 2D graphs. However, after getting over some issues with setting a path for headers: Python.h
and arrayobject.h
, I cannot get over following error: Undefined symbols for architecture arm64
, namely,
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
My main file (an example I took from Matplotlib files):
#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
Please, note: The main purpose of my programme in C++ was to solve "some" PDEs system, which I already accomplished, and I know that it works (I checked the plotted curves trends (convergence etc.) and values in MS Excel), however, plotting the values in MS Excel is very slow, hence counter-productive.
I don't have experiences with plotting 2D graphs in C++. So, if there is any easier way (library etc.) to plot 2D graphs in C++ (macOS, Clion, amr64 M1), I don't need to stick with Matplotlib.
Thanks
question from:
https://stackoverflow.com/questions/65944672/clion-macos-matplotlib-undefined-symbols-for-m1-macbook-arm64