【发布时间】:2014-09-01 19:28:08
【问题描述】:
我是使用 gdb 的新手,所以我想从使用一个打印“Hello”的简单程序开始
#include<stdio.h>
main(){
printf("Hello!\n");
}
另存为 hello.c,然后输入 gdb。根据教程打开后,我键入“file hello.c”以将程序加载到调试器中,但我收到以下消息:
This GDB was configured as "x86_64-linux-gnu".
"hello.c": not in executable format: File format not recognized
所以我输入了“gcc -Wall -g hello.c -o hello”并得到了这条消息:
hello.c:3:1: warning: return type defaults to âintâ [-Wreturn-type] hello.c:
In function âmainâ: hello.c:6:1: warning: control reaches end of non-void function [-Wreturn-type]
然后我用 int main 编辑了 main 并在代码中添加了 return 0。我又做了一次,没有错误,所以我输入了 gdb ./hello 并且它起作用了...我应该始终将我的 mains 作为 int main 并包含 return 0 吗?
【问题讨论】:
-
您调试已编译的可执行文件,而不是源代码。
-
您的程序不正确。将 main 声明为
int main()或最好是int main (int argc, char**argv) -
不要忘记右大括号
}之前的return 0;