使用matplotlib cpp时出现非常奇怪的链接器错误,如何修复? 我在大学的C++项目中工作(我不能选择Python,我的教授决定这样),我需要使用MatPuttLIB CPP(),我有一个MacBook,它有高的Seela103.6新安装的和XCODE 10.1,所以我做了如下: 从Github下载zip,解压缩并将matplotlibcpp.h放在我的项目文件夹中 关于找不到库,出现了一些错误,因此我修复了在Python/Python.h之前添加Python/和/usr/local/include/include/之前添加numpy/arrayobject.h的问题。这就是库matplotlibcpp.h的第一行现在的样子: 现在,当我添加任何函数,如plt::plot({1,2,3,4})时,它编译并给出链接器错误提示,它告诉我:
我在终端上得到了一个使用使用matplotlib cpp时出现非常奇怪的链接器错误,如何修复? 我在大学的C++项目中工作(我不能选择Python,我的教授决定这样),我需要使用MatPuttLIB CPP(),我有一个MacBook,它有高的Seela103.6新安装的和XCODE 10.1,所以我做了如下: 从Github下载zip,解压缩并将matplotlibcpp.h放在我的项目文件夹中 关于找不到库,出现了一些错误,因此我修复了在Python/Python.h之前添加Python/和/usr/local/include/include/之前添加numpy/arrayobject.h的问题。这就是库matplotlibcpp.h的第一行现在的样子: 现在,当我添加任何函数,如plt::plot({1,2,3,4})时,它编译并给出链接器错误提示,它告诉我:,python,c++,xcode,macos,matplotlib,Python,C++,Xcode,Macos,Matplotlib,我在终端上得到了一个使用-I,-l标志通过g++编译的示例,它没有运行,它说导入错误:。我如何解决这个问题?谢谢你善良的陌生人 编辑1: 我修改了引用库的头,Xcode现在给我的警告与编译器相同(不推荐的registeruse)和错误(linker),现在看起来是这样的: #pragma once #include <algorithm> #include <array> #include <cstdint> // <cstdint> requi
-I
,-l
标志通过g++编译的示例,它没有运行,它说导入错误:
。我如何解决这个问题?谢谢你善良的陌生人
编辑1:
我修改了引用库的头,Xcode现在给我的警告与编译器相同(不推荐的register
use)和错误(linker),现在看起来是这样的:
#pragma once
#include <algorithm>
#include <array>
#include <cstdint> // <cstdint> requires c++11 support
#include <functional>
#include <iostream>
#include <unordered_map>
#include <map>
#include <numeric>
#include <stdexcept>
#include <unordered_map>
#include <vector>
#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 </usr/local/include/include/numpy/arrayobject.h>
#pragma一次
#包括
#包括
#include//需要c++11支持
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#如果不带NUMPY的ifndef
#定义NPY\u否\u已弃用\u API NPY\u 1\u 7\u API\u版本
#包括
您是否按照此处提到的说明链接到python库:g++basic.cpp-I/usr/include/python2.7-lpython2.7
也许您有一个不同的/更新版本的python?感谢您的时间,我所做的和现在再次尝试的是g++main.cpp-std=c++11-I/usr/include/python2.7-lpython2.7
,但它说/matplotlibcpp.h:15:10:致命错误:“未找到Python/Python.h”文件#include^~~~~~~~~~~~~~~生成了1个错误代码>。我有python2.7.10和Python3.8.0,如何正确链接它?请查看/usr/include/python2.7
中的文件夹结构,您可能需要删除原始修复程序。意思是去掉添加到标题中的Python/
前缀。在/usr/include/python2.7
中,我可以找到所有库,包括Python.h
,还有什么我应该查找的吗?正如您在文件#include
中所说,我引用了这个库,它在Xcode中正确地再现了终端编译给我的错误,这以前没有发生过,它仍然给我上一个错误,如帖子中所示。你是否像这里提到的那样链接到python库:g++basic.cpp-I/usr/include/python2.7-lpython2.7
也许你有一个不同/更新版本的python?谢谢你的时间,我所做的和现在再次尝试的是g++main.cpp-std=c++11-I/usr/include/python2.7-lpython2.7
,但它说/matplotlibcpp.h:15:10:致命错误:“Python/Python.h”文件找不到#include^~~~~~~~~~~生成了一个错误代码>。我有python2.7.10和Python3.8.0,如何正确链接它?请查看/usr/include/python2.7
中的文件夹结构,您可能需要删除原始修复程序。意思是去掉添加到标题中的Python/
前缀。在/usr/include/python2.7
中,我可以找到所有库,包括Python.h
,还有什么我应该查找的吗?正如您在文件#include
中所说,我引用了这个库,它在Xcode中正确地再现了终端编译给我的错误,这是以前没有发生过的,它仍然给我以前的错误,如帖子中所示。
#include "matplotlibcpp.h"
using namespace std;
namespace plt = matplotlibcpp;
int main(...) {
...
}
Undefined symbols for architecture x86_64:
"_PyCObject_AsVoidPtr", referenced from:
_import_array() in main.o
"_PyCObject_Type", referenced from:
_import_array() in main.o
"_PyErr_Format", referenced from:
_import_array() in main.o
"_PyErr_Print", referenced from:
matplotlibcpp::detail::_interpreter::_interpreter() in main.o
matplotlibcpp::detail::_interpreter::import_numpy() in main.o
"_PyErr_SetString", referenced from:
matplotlibcpp::detail::_interpreter::import_numpy() in main.o
_import_array() in main.o
"_PyExc_AttributeError", referenced from:
_import_array() in main.o
"_PyExc_ImportError", referenced from:
matplotlibcpp::detail::_interpreter::import_numpy() in main.o
"_PyExc_RuntimeError", referenced from:
_import_array() in main.o
"_PyFunction_Type", referenced from:
matplotlibcpp::detail::_interpreter::safe_import(_object*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in main.o
"_PyImport_Import", referenced from:
matplotlibcpp::detail::_interpreter::_interpreter() in main.o
"_PyImport_ImportModule", referenced from:
_import_array() in main.o
"_PyObject_CallMethod", referenced from:
matplotlibcpp::detail::_interpreter::_interpreter() in main.o
"_PyObject_CallObject", referenced from:
bool matplotlibcpp::plot<double, double>(std::__1::vector<double, std::__1::allocator<double> > const&, std::__1::vector<double, std::__1::allocator<double> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in main.o
"_PyObject_GetAttrString", referenced from:
matplotlibcpp::detail::_interpreter::safe_import(_object*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in main.o
_import_array() in main.o
"_PyString_FromString", referenced from:
bool matplotlibcpp::plot<double, double>(std::__1::vector<double, std::__1::allocator<double> > const&, std::__1::vector<double, std::__1::allocator<double> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in main.o
matplotlibcpp::detail::_interpreter::_interpreter() in main.o
"_PyTuple_New", referenced from:
bool matplotlibcpp::plot<double, double>(std::__1::vector<double, std::__1::allocator<double> > const&, std::__1::vector<double, std::__1::allocator<double> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in main.o
matplotlibcpp::detail::_interpreter::_interpreter() in main.o
"_PyTuple_SetItem", referenced from:
bool matplotlibcpp::plot<double, double>(std::__1::vector<double, std::__1::allocator<double> > const&, std::__1::vector<double, std::__1::allocator<double> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in main.o
"_Py_Finalize", referenced from:
matplotlibcpp::detail::_interpreter::~_interpreter() in main.o
"_Py_Initialize", referenced from:
matplotlibcpp::detail::_interpreter::_interpreter() in main.o
"_Py_SetProgramName", referenced from:
matplotlibcpp::detail::_interpreter::_interpreter() in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
symbol(s) not found for architecture x86_64
linker command failed with exit code 1 (use -v to see invocation)
Ld /Users/giovannigravili/Library/Developer/Xcode/DerivedData/brain-3.X-hclmildbujzoynbfpgamcnjyrxig/Build/Products/Debug/brain-3.X normal x86_64 (in target: brain-3.X)
cd /Users/giovannigravili/Documents/GitHub/brain_project/brain-3.X
export MACOSX_DEPLOYMENT_TARGET=10.14
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -L/Users/giovannigravili/Library/Developer/Xcode/DerivedData/brain-3.X-hclmildbujzoynbfpgamcnjyrxig/Build/Products/Debug -F/Users/giovannigravili/Library/Developer/Xcode/DerivedData/brain-3.X-hclmildbujzoynbfpgamcnjyrxig/Build/Products/Debug -filelist /Users/giovannigravili/Library/Developer/Xcode/DerivedData/brain-3.X-hclmildbujzoynbfpgamcnjyrxig/Build/Intermediates.noindex/brain-3.X.build/Debug/brain-3.X.build/Objects-normal/x86_64/brain-3.X.LinkFileList -mmacosx-version-min=10.14 -Xlinker -object_path_lto -Xlinker /Users/giovannigravili/Library/Developer/Xcode/DerivedData/brain-3.X-hclmildbujzoynbfpgamcnjyrxig/Build/Intermediates.noindex/brain-3.X.build/Debug/brain-3.X.build/Objects-normal/x86_64/brain-3.X_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -stdlib=libc++ -Xlinker -dependency_info -Xlinker /Users/giovannigravili/Library/Developer/Xcode/DerivedData/brain-3.X-hclmildbujzoynbfpgamcnjyrxig/Build/Intermediates.noindex/brain-3.X.build/Debug/brain-3.X.build/Objects-normal/x86_64/brain-3.X_dependency_info.dat -o /Users/giovannigravili/Library/Developer/Xcode/DerivedData/brain-3.X-hclmildbujzoynbfpgamcnjyrxig/Build/Products/Debug/brain-3.X
#pragma once
#include <algorithm>
#include <array>
#include <cstdint> // <cstdint> requires c++11 support
#include <functional>
#include <iostream>
#include <unordered_map>
#include <map>
#include <numeric>
#include <stdexcept>
#include <unordered_map>
#include <vector>
#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 </usr/local/include/include/numpy/arrayobject.h>