首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取Dwarf错误版本'4‘

获取Dwarf错误版本'4‘
EN

Stack Overflow用户
提问于 2014-12-01 04:03:16
回答 2查看 12.8K关注 0票数 3

我的学校项目出了点问题。我认为这可能是我使用指针的错误,但我不确定为什么我会得到这个错误。这段代码是不完整的,但我一直在尝试测试它。你知道为什么我会收到这个错误吗?它意味着什么?谢谢!

来自Cygwin终端的错误

代码语言:javascript
复制
-bash-3.2$ make clean
rm -rf *.o simulate
-bash-3.2$ make simulate
g++ -c -g Main.cpp
g++ -c -g Maze.cpp
g++ Main.o Maze.o -o simulate
/usr/bin/ld: Dwarf Error: found dwarf version '4', this reader only handles version 2 information.
Maze.o: In function `Maze::createMaze(char*)':
Maze.cpp:(.text+0x49): undefined reference to `Node::Node(char)'
collect2: error: ld returned 1 exit status
make: *** [simulate] Error 1

Main.cpp

代码语言:javascript
复制
#include <iostream>
#include <fstream>
#include <string>
#include "Maze.h"
using namespace std;

int main()
{
    int array_size = 1024;
    char * mazeArray = new char[array_size];
    int position = 0;
    string mazeName;
    Maze Maze1;

    cout << "Enter the name of the maze file: ";
    getline(cin, mazeName);

    ifstream fin(mazeName.c_str());
    //File opened successfully
    if(fin.is_open())
    {
        while(!fin.eof() && position < array_size)
        {
            fin.get(mazeArray[position]); //reading one character from file to mazeArray
            position++;
        }
        mazeArray[position-1] = '\0'; //placing character mazeArray terminating character

        for(int i = 0; mazeArray[i] != '\0'; i++){
            if(isspace(mazeArray[i]))
                mazeArray[i] = mazeArray[i+1];
        }

        cout << "Displaying mazeArray..." << endl << endl;
        //this loop display all the charaters in mazeArray till \0 
        for(int i = 0; mazeArray[i] != '\0'; i++)
        {
            cout << mazeArray[i];
        }
        cout << endl;

        Maze1.createMaze(mazeArray);

    }
    else //file could not be opened
    {
        cout << "File could not be opened." << endl;
    }

    return 0;
}

Maze.h

代码语言:javascript
复制
#ifndef MAZE_H
#define MAZE_H
#include <string>
#include <sstream>
#include <vector>

#include "Node.h"
using namespace std;

class Maze
{
        public:
            void createMaze(char*);
            void availablePaths();
            void displayPath();
            void moveNorth();
            void moveSouth();
            void moveEast();
            void moveWest();
            int getroomCount();
            char getpathHistory();
            char getcurrentRoom();

        private:
            int roomCount;
            char pathHistory[];
            Node* currentRoom;
            Node* nodeArray[12];
            struct isPath;
                vector<Node*> nodeVector;

};

#endif

Maze.cpp

代码语言:javascript
复制
#include <iostream>
#include <string>

#include "Maze.h"

using namespace std;

Node* Node1;

void Maze::createMaze(char *inFile){
    int count = 0;

    //Creates Nodes for Maze
    for(int ii = 0; ii <= 12; ii++){
        Node1 = new Node(inFile[count]);
        nodeVector.push_back(Node1);
        count = count + 5;

        //If there is not another node break out of the for loop.
        if(inFile[count] == '\0'){
            break;
        }
    }

}

void Maze::availablePaths(){

}

void Maze::displayPath(){

}

void Maze::moveNorth(){

}

void Maze::moveSouth(){

}

void Maze::moveEast(){

}

void Maze::moveWest(){

}

int Maze::getroomCount(){

}

char Maze::getpathHistory(){

}

char Maze::getcurrentRoom(){

}

Node.h

代码语言:javascript
复制
#ifndef NODE_H
#define NODE_H
#include <string>
#include <map>
#include <sstream>
using namespace std;

class Node
{
        public:
                Node(char);
                void setNodeName(char);
                void attachNewNode(Node, int);
                Node *getAttachedNode(int);
        private:
                char name; // Title that is displayed above the menu.
                Node *attachedNodes[4];
};

#endif

Node.cpp

代码语言:javascript
复制
#include <iostream>
#include <string>
#include <vector>

#include "Node.h"
using namespace std;

Node::Node(char name) : name(name) {

} 

void Node::setNodeName(char tempName){
    name = tempName;
}

void Node::attachNewNode(Node temp, int direction){
    attachedNodes[direction] = temp;
}

Node Node::getAttachedNode(int direction){
    return attachedNodes[direction];
}

makefile

代码语言:javascript
复制
#!/bin/bash
#file:makefile
CC = g++
CFLAGS = -c -g

simulate: Main.o Maze.o
    $(CC) Main.o Maze.o -o simulate

Main.o: Main.cpp Maze.h
    $(CC) $(CFLAGS) Main.cpp

Maze.o: Maze.cpp Menu.h Node.h
    $(CC) $(CFLAGS) Maze.cpp
Node.o: Node.cpp Node.h
    $(CC) $(CFLAGS) Node.cpp

clean:
    rm -rf *.o simulate
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-12-01 04:09:52

问题本身并不在你的代码中。

一个问题是,您的链接命令失败,因为您没有链接所有的目标文件。您需要链接Main.oMaze.oNode.o来创建可执行文件:

代码语言:javascript
复制
g++ Main.o Maze.o Node.o -o simulate

另一个问题是你的编译器比链接器新。编译器正在使用Dwarf版本4生成调试信息,但您的链接器(/usr/bin/ld)只能理解Dwarf版本2。

代码语言:javascript
复制
/usr/bin/ld: Dwarf Error: found dwarf version '4', this reader only handles
version 2 information.

您需要将链接器更新为与您正在使用的编译器兼容的更新版本。

或者,正如jannebcomment中建议的那样,您可以在编译和链接行中使用-gdwarf-2。在makefile

代码语言:javascript
复制
CFLAGS = -c -gdwarf-2

FILES.cpp = Main.cpp Maze.cpp Node.cpp
FILES.o   = $(FILES.cpp:.cpp=.o}

simulate: $(FILES.o)
    $(CC) $(CFLAGS) $(FILES.o) -o $@

( makefile中应该只有很少一部分命令行不是宏调用;这样您就可以更容易地更改所有内容。)

您将需要删除Dwarf-4目标文件并重新编译,以避免出现错误/警告。

票数 4
EN

Stack Overflow用户

发布于 2021-09-29 06:24:49

您可以通过以下方式简单地解决此问题:

export CFLAGS='-gdwarf-2 -gstrict-dwarf'

然后,重写你的项目。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27217623

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档