2016-12-15 3 views
0

チュートリアルのコードをコンパイルしようとしていますが、ABI::CXX11 undefined reference errorがあります。ここでは、問題のコードは次のとおりです。'ClassName :: memberField [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]' 

私が見た/読んだことから、それはthe difference between std::list and std::list 2011.と関係がある。

on an other stack postから-D_GLIBCXX_USE_CXX11_ABI=0を使用すると問題は解決しますが、何も変更されませんでした(C++コンパイラの追加オプションとリンカの追加オプションに追加しようとしました)。コード・リスト-2 Node.cppで

答えて

1

#include "Node.hpp" 

list<Node *> nodes; 

Node::Node() { 
    // ... 

は次のようになります。

#include "Node.hpp" 

list<Node *> Node::nodes; 

Node::Node() { 
    // ... 

Node::がなければ、あなたは、このようにグローバル変数静的メンバNode::nodesとは無関係のnodes、宣言しています静的メンバー変数が適切な定義を必要とするため、未定義の参照です。

関連する問題