我正在尝试从教程中编译代码,但是我得到了一个
代码清单2 Node.cpp:
这是我收到的错误信息:
根据我所看/读到的,这似乎与 std::list 与 std::list 2011 之间的区别有关。
根据我在其他堆栈帖子中所读到的,使用
ABI::CXX11未定义引用错误
。 这里是有问题的代码:
代码清单1 Node.hpp:
#ifndef NODE_HPP
#define NODE_HPP
#include "Node.hpp"
#include <list>
using std::__cxx11::list;//I am forced to use std-c++11 because of wxWidgets 3.0.2
#include <cstdlib>
class Node {
public:
Node();
Node(const Node& orig);
virtual ~Node();
void setParent(Node * parent);
Node * getParent();
list<Node *> &getChildren();
static list<Node *> &getNodes();
private:
static list<Node *> nodes;
protected:
list<Node *> children;
Node * parent;
};
#endif /* NODE_HPP */
代码清单2 Node.cpp:
#include <cstdlib>
#include "Node.hpp"
list<Node *> nodes;
Node::Node() {
parent = NULL;
nodes.push_back(this);//line 23
}
Node::Node(const Node& orig) {
}
Node::~Node() {
nodes.remove(this);//line 30
}
void Node::setParent(Node * p){
if( p == NULL && parent != NULL ) {
parent->children.remove(this);
parent = NULL;
} else if( p->getParent() != this ) {
parent = p;
parent->children.push_back(this);
}
}
Node * Node::getParent(){
return parent;//line 53
}
list<Node *> &Node::getChildren(){
return children;
}
list<Node *> &Node::getNodes(){
return nodes;
}
这是我收到的错误信息:
build/Debug/MinGW-Windows/Node.o: In function `ZN4NodeC2Ev':
E:\Projects\CPP\wxWidgets/Node.cpp:23: undefined reference to `Node::nodes[abi:cxx11]'
build/Debug/MinGW-Windows/Node.o: In function `ZN4NodeD2Ev':
E:\Projects\CPP\wxWidgets/Node.cpp:30: undefined reference to `Node::nodes[abi:cxx11]'
build/Debug/MinGW-Windows/Node.o: In function `ZN4Node8getNodesB5cxx11Ev':
E:\Projects\CPP\wxWidgets/Node.cpp:53: undefined reference to `Node::nodes[abi:cxx11]'
根据我所看/读到的,这似乎与 std::list 与 std::list 2011 之间的区别有关。
根据我在其他堆栈帖子中所读到的,使用
-D_GLIBCXX_USE_CXX11_ABI=0
应该可以解决此问题,但实际上没有任何变化(我尝试将其添加到C++编译器附加选项和链接器附加选项中)。