2017-12-04 46 views
0

Ubuntu 16.04で単純な "hello world" C++プログラムをデバッグしようとしていますが、gdbが実行可能ファイル形式を認識できません。ただし、コマンドラインで実行可能ファイルを正常に実行することができます。 は、ここで私は、デバッグに実行形式でないgdbエラー:ファイル形式が認識されない

g++ -g TestProject.cpp -o hello 

次にコマンドを使用してTestProject.cppプログラムファイルをコンパイル

#include <iostream> 
using namespace std; 

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

コードですが、私は

gdb ./hello 

は、私がgetコマンドに次のエラーを与えますメッセージ

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仮想マシンで同じプログラムをデバッグすることができるからです。

+0

Ubuntuマシンで何かが壊れているようです。私は別のUbuntu 16.04仮想マシンで同じプログラムをデバッグすることができるからです。 –

+0

'ファイル。/ hello'は何を与えるのですか? –

+1

'このGDBは" i686-linux-gnu "と設定されていました。おそらく、32ビット構成のgdbで64ビット実行ファイルをデバッグしようとしています。 'g ++ -m32 -g TestProject.cpp -o hello'を実行するか、64ビット構成のgdbをインストールしてください。 – ks1322

答えて

0

ks1322さんのコメントが正しいものであることをほとんど確かである:

  1. あなたはとてもあなたの./helloは、64ビットのバイナリで、64ビットのGCCをインストールした(確認のためfile ./helloを使用します)。
  2. 32ビットのみのGDBをインストールしたので、x86_64バイナリのデバッグ方法はわかりません。

修正は簡単である:(g++ -m32 ...で)32ビットモードで64ビット(32ビットおよび64ビットのバイナリをデバッグすることが可能である)GDB、又はビルドhelloをインストールします。

関連する問題