具有未定义引用和重新定位的简单程序被截断以适应错误
Simple program with undefined reference & relocation truncated to fit error
好吧,我正在youtube上学习c++教程,因为我是一个相对较新的程序员。我正在努力学习如何在创建类时使用头文件等。在本教程中,我们将学习如何使用箭头成员选择操作符。
https://www.youtube.com/watch?v=2RP4f9beidc&list=PLAE85DE8440AA6B83&索引=42
我没有使用代码块,这是他正在使用的IDE。我正在gedit上编写代码,并使用Cygwin编译和运行它。
如有任何帮助,我们将不胜感激!
这是一个简单的代码:
主要.cpp
#include <iostream>
#include "Sally.h"
using namespace std;
int main(){
Sally sallyObject;
Sally *sallyPointer = &sallyObject;
sallyObject.printCrap();
sallyPointer->printCrap();
}
Sally.cpp
#include "Sally.h"
#include <iostream>
using namespace std;
Sally::Sally()
{
}
void Sally::printCrap(){
cout << "did someone say steak?" << endl;
}
莎莉
#ifndef SALLY_H
#define SALLY_H
#include <iostream>
class Sally
{
public:
Sally();
void printCrap();
protected:
private:
};
#endif // SALLY_H
错误代码:
/tmp/ccfOEJJF.o:Main.cpp:(.text+0x15):对Sally::Sally()'
/tmp/ccfOEJJF.o:Main.cpp:(.text+0x15): relocation truncated to fit: R_X86_64_PC32 against undefined symbol
Sally::Sally()的未定义引用'/tmp/ccfOEJJF.o:Main.cpp:(.text+0x29):对Sally::printCrap()'
/tmp/ccfOEJJF.o:Main.cpp:(.text+0x29): relocation truncated to fit: R_X86_64_PC32 against undefined symbol
Sally::printCrap()的未定义引用'/tmp/ccfOEJJF.o:Main.cpp:(.text+0x35):对Sally::printCrap()'
/tmp/ccfOEJJF.o:Main.cpp:(.text+0x35): relocation truncated to fit: R_X86_64_PC32 against undefined symbol
Sally::printCrap()的未定义引用'collect2:错误:ld返回1退出状态
为此在cygwin中输入的命令必须是
g++ Sally.cpp Main.cpp
命令行中不包含头文件。作为一条建议,请查找如何使用makefiles。
在testsuite/Makefile
中,我将prog的规则更改为:
prog.o: prog.c
$(CC) -c -o $@ $<
prog.exe: prog.o
$(CC) -o $@ $<
这推动了事情的发展——我不确定它是否正确——但它在protos.h
中继续出现问题,因为已经有Elf_[ESP]hdr类型的系统头定义。。。对于中的所有原型、定义和参考,我不得不将它们更改为pelf_[ESP]hdr
protos.h
chrpath.c
elf.c
killrpath.c
- 显示错误输出的简单数组排序程序
- 简单C++"Hello World"程序的执行时间长
- 而循环:简单的除法程序输出零,不明白为什么
- 为什么一个简单的程序不能立即启动
- 使用简单两相锁定的并发程序
- [[可能]]和[[不太可能]]影响程序汇编的简单示例?
- GDB 8.1 无法在单线程简单程序中跟踪 std::string 变量的值
- 多线程 gtkmm 应用程序最简单的示例
- 我写了一个简单的矢量程序,在其中我得到了以下输出。你能帮我理解它的输出吗?
- 如何使用cmake和Visual Studio 2019编译简单的Windows应用程序?
- 试图解决这个简单的C++程序,但我被困在某个地方
- 我已经安装了用于c++编程的升华3,但在编写了一个简单的程序后,我遇到了以下错误
- 无法编译简单的C++17程序
- 如何设置一个简单的CGAL+Qt程序
- Cmake无法在qt-creater/collect2上编译简单的测试程序:错误:ld
- 令牌之前的简单程序预期标识符'('
- 使用Cmake进行简单的CUDA程序
- 我创建了一个简单的程序,但有些地方不对劲
- 编译简单的多文件类程序时出现未定义的引用错误
- 程序简单,没有调用堆栈,"inpossible"查找错误