您的位置:首页 > 其它

gcc、g++和gdb的使用

2012-10-09 13:48 197 查看
gcc编译运行C程序

#include <stdio.h>

int main(void)

{

printf ("Hello world, Linux programming!\n");

return 0;

}

1、编写程序vim hello.c保存后退出

2、编译代码gcc hello.c

3、添加可执行权限chmod +x a.out

4、运行程序./a.out

5、运行结果

Hello world, Linux programming!

1、编写程序vim hello.c保存后退出

2、编译代码gcc hello.c -o hello.out

3、添加可执行权限chmod +x hello.out

4、运行程序./hello.out

5、运行结果

Hello world, Linux programming!

gdb的使用

1、在编译程序时加入调试信息

gcc -g -o hello.debug hello.c

2、启动gdb

gdb

3、在gdb中加载需要调试的程序

file hello.debug

4、在gdb中查看代码

list 1

5、在程序中加入断点

break 5

6、运行程序

run

在断点处停下输入next或者step继续

7、变量的查看

print i

g++编译运行c++程序

#include <iostream>

using namespace std;

int main()

{

cout<<"Hello!\n";

return 0;

}

1、编写程序vim hello.cpp保存后退出

2、编译代码g++ hello.pp

3、添加可执行权限chmod +x a.out

4、运行程序./a.out

5、运行结果

Hello!

1、编写程序vim hello.cpp保存后退出

2、编译代码gcc hello.cpp -o hello.out

3、添加可执行权限chmod +x hello.out

4、运行程序./hello.out

5、运行结果

Hello!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: