c++ - gdb 错误不是可执行格式 : File format not recognized

标签 c++ gdb ubuntu-16.04

我正在尝试在 Ubuntu 16.04 上调试一个简单的“hello world”C++ 程序,但 gdb 无法识别可执行文件格式。但是,我能够在命令行上成功运行可执行文件。 这是代码

#include <iostream>
using namespace std;

int main() {
    cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    return 0;
}

我使用命令编译程序文件TestProject.cpp

g++ -g TestProject.cpp -o hello

然后要调试,我给出命令

gdb ./hello

我收到以下错误信息

GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
"/home/<home>/./hello": not in executable format: File format not recognized

Ubuntu 机器似乎有问题。因为我能够在另一个 Ubuntu 16.04 虚拟机上调试相同的程序。

最佳答案

几乎可以肯定 ks1322 的评论是正确的:

  1. 您已经安装了 64 位 GCC,所以您的 ./hello 是一个 64 位二进制文​​件(使用 file ./hello 来确认)。<
  2. 您安装了仅 32 位的 GDB,因此它不知道如何调试 x86_64 二进制文件。

修复很简单:安装 64 位 GDB(能够调试 32 位和 64 位二进制文​​件),在 32 位模式下构建 hello (使用 g++ -m32 ...)。

关于c++ - gdb 错误不是可执行格式 : File format not recognized,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47639685/

相关文章:

c++ - 将视频文件加载到 C++ 中的缓冲区中

c++ - C++ 中类型错误的参数

c - 检查传递给 gdb 中函数的多维数组

c - Eclipse中的MINGW-HOME为相对路径时找不到GDB

c - buf(main函数中的局部变量)的地址是多少?

c# - 从 C# 调用 C++ DLib 导致错误分配异常

c++ - 指向指针赋值的指针

iis - Haproxy 粘性 session

python - 导入错误: No module named 'django' uWSGI Django Nginx Ubuntu 16. 04 Python3.6

python - 尝试使用Dockerfile下载requirements.txt时哈希值错误