寒江独钓

博客园 首页 新随笔 联系 订阅 管理

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

posted on 2012-10-17 21:15  X.W.LIU  阅读(216)  评论(0编辑  收藏  举报