`
mmdev
  • 浏览: 12845121 次
  • 性别: Icon_minigender_1
  • 来自: 大连
文章分类
社区版块
存档分类
最新评论

[GCC for C]编译选项---IDE掩盖下的天空

 
阅读更多

编译选项

---------IDE掩盖下的天空

/***************************************
* gcc for c language
***************************************/

Single Source to Executable
$ gcc helloworld.c [-o howdy]
默认生成的名字a.exe
______________________________________
Source File to Object File
$ gcc -c helloworld.c [-o harumph.o]
默认生成的名字与原文件名一致,后缀为.o
-c告知不但保留object文件,而且忽略连接过程
______________________________________
Multiple Source Files to Executable
$ gcc hellomain.c sayhello.c -o hello
______________________________________
Preprocessing
$ gcc -E helloworld.c [-o helloworld.i]
默认不输出文件,若输出则为.i文件
-E把宏展开后的代码情况
____________________________________
Generating Assembly Language
$ gcc -S helloworld.c
-S生成hellowordl.s汇编语言文件
____________________________________
Creating a Static Library
1、生成.o文件
$ gcc -c hellofirst.c hellosecond.c
2、生成.a文件
$ ar -r libhello.a hellofirst.o hellosecond.o
注意静态库的命名规则
3、连接
$ gcc twohellos.c libhello.a -o twohellos
____________________________________
Creating a Shared Library
1、生成.o文件
$ gcc -c -fpic shellofirst.c shellosecond.c
-fpic 使得.o输出模块以地址可定向的方式产生。[pic:position independent code]
2、生成.so
$ gcc -shared shellofirst.o shellosecond.o -o hello.so
3、连接
$ gcc stwohellos.c hello.so -o stwohellos
注意:1、2可以合并为
$ gcc -fpic -shared shellofirst.c shellosecond.c -o hello.so
_____________________________________
Overriding the Naming Convention
$ gcc -xc helloworld.jxj -o helloworld
-xc对于C语言的源代码,默认后缀为.c,但别的后缀文件也可以当作c来用,那就要加-x选项
_______________________________________
Create a header file
$ gcc sayhello.c -aux-info sayhello.h
$ gcc *.c -aux-info prototypes.h
不过这样产生的头文件,包含的函数原型太多,除了用户自定义的函数外,标准库中的函数原型都列出来了


编译选项

---------IDE掩盖下的天空

/***************************************
* gcc for c language
***************************************/

Single Source to Executable
$ gcc helloworld.c [-o howdy]
默认生成的名字a.exe
______________________________________
Source File to Object File
$ gcc -c helloworld.c [-o harumph.o]
默认生成的名字与原文件名一致,后缀为.o
-c告知不但保留object文件,而且忽略连接过程
______________________________________
Multiple Source Files to Executable
$ gcc hellomain.c sayhello.c -o hello
______________________________________
Preprocessing
$ gcc -E helloworld.c [-o helloworld.i]
默认不输出文件,若输出则为.i文件
-E把宏展开后的代码情况
____________________________________
Generating Assembly Language
$ gcc -S helloworld.c
-S生成hellowordl.s汇编语言文件
____________________________________
Creating a Static Library
1、生成.o文件
$ gcc -c hellofirst.c hellosecond.c
2、生成.a文件
$ ar -r libhello.a hellofirst.o hellosecond.o
注意静态库的命名规则
3、连接
$ gcc twohellos.c libhello.a -o twohellos
____________________________________
Creating a Shared Library
1、生成.o文件
$ gcc -c -fpic shellofirst.c shellosecond.c
-fpic 使得.o输出模块以地址可定向的方式产生。[pic:position independent code]
2、生成.so
$ gcc -shared shellofirst.o shellosecond.o -o hello.so
3、连接
$ gcc stwohellos.c hello.so -o stwohellos
注意:1、2可以合并为
$ gcc -fpic -shared shellofirst.c shellosecond.c -o hello.so
_____________________________________
Overriding the Naming Convention
$ gcc -xc helloworld.jxj -o helloworld
-xc对于C语言的源代码,默认后缀为.c,但别的后缀文件也可以当作c来用,那就要加-x选项
_______________________________________
Create a header file
$ gcc sayhello.c -aux-info sayhello.h
$ gcc *.c -aux-info prototypes.h
不过这样产生的头文件,包含的函数原型太多,除了用户自定义的函数外,标准库中的函数原型都列出来了

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics