bash:./main:无法执行二进制文件:Exec格式错误
bash: ./main: cannot execute binary file: Exec format error
我知道这个问题以前已经问过,但是在我的情况下,这些答案都没有帮助。
我已经安装了Ubuntu 18.04 LTS,当我尝试运行C 程序时,我会收到此错误:
bash: ./main: cannot execute binary file: Exec format error
我知道,当尝试在64位计算机上运行32位程序时,会发生此错误。但是在终端输出中使用文件主
main: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
使用UNAME -A输出
Linux florian 4.15.0-46-generic #49-Ubuntu SMP Wed Feb 6 09:33:07 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
我忽略了什么?
预先感谢
编辑:
我使用
编译程序g++ -Wall -c -std=c++14 -o main main.cpp
这就是文件夹的外观:
https://www.bilder-upload.eu/bild-cf6106-15533082433.png.html
游戏。
尝试在没有-c标志的情况下编译文件给我这个终端输出:
/tmp/ccBqZfJw.o: In function `main':
main.cpp:(.text+0x63): undefined reference to `Sep::Game::Game()'
main.cpp:(.text+0xaf): undefined reference to `Sep::Game::loadConfig(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
main.cpp:(.text+0xec): undefined reference to `Sep::Game::printMap()'
main.cpp:(.text+0x102): undefined reference to `Sep::Game::addWorm(int, int)'
main.cpp:(.text+0x121): undefined reference to `Sep::Game::printMap()'
main.cpp:(.text+0x13c): undefined reference to `Sep::Game::move(int, int, int)'
main.cpp:(.text+0x152): undefined reference to `Sep::Game::addWorm(int, int)'
main.cpp:(.text+0x17b): undefined reference to `Sep::Game::addWorm(int, int)'
main.cpp:(.text+0x19a): undefined reference to `Sep::Game::printMap()'
main.cpp:(.text+0x1b5): undefined reference to `Sep::Game::move(int, int, int)'
main.cpp:(.text+0x1d0): undefined reference to `Sep::Game::move(int, int, int)'
main.cpp:(.text+0x1eb): undefined reference to `Sep::Game::move(int, int, int)'
main.cpp:(.text+0x1f7): undefined reference to `Sep::Game::printMap()'
main.cpp:(.text+0x20d): undefined reference to `Sep::Game::addWorm(int, int)'
main.cpp:(.text+0x233): undefined reference to `Sep::Game::addWorm(int, int)'
main.cpp:(.text+0x25e): undefined reference to `Sep::Game::move(int, int, int)'
main.cpp:(.text+0x26f): undefined reference to `Sep::Game::~Game()'
main.cpp:(.text+0x2b9): undefined reference to `Sep::Game::~Game()'
collect2: error: ld returned 1 exit status
编辑:
在AME时尝试使用其他文件对其进行编译后,似乎我们越来越接近解决方案,但是仍然存在一些错误:
命令:
g++ -Wall -std=c++14 -o main main.cpp Field.cpp Game.cpp
输出:
/tmp/ccrCypxF.o: In function `main':
main.cpp:(.text+0x26f): undefined reference to `Sep::Game::~Game()'
main.cpp:(.text+0x2b9): undefined reference to `Sep::Game::~Game()'
/tmp/ccxLZpfi.o: In function `Sep::Game::Game()':
Game.cpp:(.text+0x1f): undefined reference to `vtable for Sep::Game'
/tmp/ccxLZpfi.o: In function `Sep::Game::printMap()':
Game.cpp:(.text+0x104e): undefined reference to `Sep::Field::Field()'
/tmp/ccxLZpfi.o: In function `Sep::Game::move(int, int, int)':
Game.cpp:(.text+0x133b): undefined reference to `Sep::Field::Field()'
collect2: error: ld returned 1 exit status
您应该在同一命令中编译所有文件,以便可以将它们链接到可执行文件中:
g++ -Wall -std=c++14 -o main main.cpp Field.cpp Game.cpp
嗨,欢迎在此处。
您应该解释您如何编译和链接程序,因为恐怕那里有问题。
问题是您的文件是不是可执行文件。如文件实用程序所述,它是 recocatable 文件,而不是可执行文件。
要了解重新定位和可执行文件之间的差异的更多信息,您可以在此处查看此答案:以精灵格式可执行文件和可重新定位之间有什么区别?
编辑
由于OP提供了更多详细信息,因此是解决方案。
1)丢弃-c标志。正如其他人所说的那样,那是很明显的;
2)在您的编译命令中添加所有.cpp文件:
g++ -Wall -std=c++14 -o main main.cpp Field.cpp Game.cpp
相关文章:
- 正在读取二进制文件(is_open)
- 在C++中将类(带有Vector成员)保存为二进制文件
- 如何从二进制文件中读取字符串
- 保存/加载大量短数组到二进制文件
- 从二进制文件中读取整数数组
- Android 在编译二进制文件时重建静态库
- 在 C++ 中将双精度变量写入二进制文件
- clang 的 libFuzzer 可以在同一二进制文件中测试超过 1 个 API 吗?
- C++:实际上不是从二进制文件中读取
- 如何从二进制文件中的给定符号中获取调用程序图
- 将内部带有矢量的结构保存/读取到二进制文件中
- 编译多个C++文件.调用二进制文件以运行代码
- 如何使用位字段将数据从二进制文件复制到结构中?
- uint8_t同一二进制文件的不同十进制值
- C++单个生成文件多个二进制文件
- 尝试将数字写入二进制文件时引发异常
- -bash:/a.out:无法执行二进制文件:Exec格式错误
- bash:./main:无法执行二进制文件:Exec格式错误
- bash:即使二进制和Linux是64位的,也无法执行二进制文件:Exec格式错误
- 使用apache thrift通过exec执行二进制文件