linux环境下c语言编程——–gdb调式实例

1)记得我在做刘涛涛那个面试题目的时候,宏的展开实在令人烦恼,用vs也同样可以得到欲编译得到的文件,详情可查看:

     http://blog.csdn.net/chief1985/article/details/2132919 

   查看展开后的宏:
   vc6:
   project   menu->settings  
   project   settings   dialog  
   C/C++   tab  
   category   :   preprocessor  
   Project   options:  
   最后加上   /P  

   rebuild   all,会产生于.cpp同名的.i文件。在这里宏被展开了。注意此时,编译器会报错,这是没有关系的,因为我们只是想得到.i文件。

  其他编译器类似。

   在linux环境下,我们用-E参数即可: 

   [root@localhost helloworld]# gcc -E helloworld.c > hello.txt

    > hello.txt是将预编译得到的输出内容输出重定向到同目录下的hello.txt中。

   -E 选项告诉GCC在预处理后停止编译过程

2) 

[root@localhost helloworld]# gcc -E helloworld.c >hello.txt

 

[root@localhost helloworld]# gcc -x cpp-output -c hello.txt -o hello.o

//-c hello.txt编译为目标代码

//  -x 使GCC从指定步骤开始编译

[root@localhost helloworld]# gcc hello.o -o hello  //链接目标文件,生成二进制代码

[root@localhost helloworld]# ./hello                    //运行hello
PI is:3.141593
1
2
3
hello world!so easy ,linux programming

 

 

 helloworld源代码:/Files/X-W-LIU/helloworld.txt

原文链接: https://www.cnblogs.com/X-W-LIU/archive/2012/10/17/2728523.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    linux环境下c语言编程--------gdb调式实例

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/66103

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月9日 下午12:10
下一篇 2023年2月9日 下午12:10

相关推荐