編譯選項
---------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
不過這樣產生的頭文件,包含的函數原型太多,除了用戶自定義的函數外,標準庫中的函數原型都列出來了