gpt4 book ai didi

c++ - 获取矮人错误版本 '4'

转载 作者:搜寻专家 更新时间:2023-10-31 01:42:15 26 4
gpt4 key购买 nike

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

Cygwin 终端错误

-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

#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;
}

迷宫.h

#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

迷宫.cpp

#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(){

}

节点.h

#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

节点.cpp

#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];
}

生成文件

#!/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

最佳答案

问题不在你的代码本身。

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

g++ Main.o Maze.o Node.o -o simulate

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

/usr/bin/ld: Dwarf Error: found dwarf version '4', this reader only handles
version 2 information.

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

或者,作为 janneb建议 comment ,您可以在编译和链接行中使用 -gdwarf-2。在 makefile 中:

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 目标文件并重新编译以避免错误/警告。

关于c++ - 获取矮人错误版本 '4',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27217623/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com