2012年1月12日 星期四

gcc Compiler

Introduction:
The GNU C compiler is an integral part of the GNU system and was initially written by Richard Stallman. At first it only compiled C code. Later a group of volunteers started maintaining it and GCC gained the ability to support different languages such a C++, Fortran, Ada and Java


Sample:
Three file
test.c
{{{

#include "test.h"

void test(void) {
}

}}}
test.h
{{{

#ifndef TEST_H_INCLUDED
#define TEST_H_INCLUDED
void test (void);
#endif


}}}
header_test.c: include all content
{{{

#include
#include "test.h"

int main(int argc, char *argv[]) {
test();
}


}}}


Compiler order:
{{{
# Compiler the test as the object content
[Andy@localhost HEADERTEST]$ gcc -c test.c

# Linker test.o and compiler the main header file
[Andy@localhost HEADERTEST]$ gcc test.o header_test.c -o header_test

}}}





Reference:
http://stackoverflow.com/questions/672734/how-to-prevent-multiple-definitions-in-c
http://www.seas.upenn.edu/cets/answers/gcc.html

http://pages.cs.wisc.edu/~beechung/ref/gcc-intro.html

document:
http://www.google.com.tw/url?sa=t&rct=j&q=gcc+tutorial&source=web&cd=5&ved=0CEkQFjAE&url=http%3A%2F%2Fusers.encs.concordia.ca%2F~mokhov%2Fcomp444%2Ftutorials%2Fgcc.pdf&ei=ScsPT9DdGsmuiQfQlYgN&usg=AFQjCNEoLYzfKgvR2w45MaJgAV0X2E6gVQ&sig2=Jr5GLu6ZqRINbBsAjZxyzQ


http://falldog7.blogspot.com/2007/09/cc-function-definition-definitionh.html



Useful Linux command content
{{{{
-c : 只做編譯(不做連結)
-S : 輸出組譯碼
-E : 將預處理結果顯示
-o filename : 指定輸出檔名
-ansi : 程式要求依據ansi c標準
-Dmacro : 使定義巨集(marco)為有效
-Dmarco=defn : 使定義巨集(marco)為defn
-Wa,option : 將選項(option)傳給組譯器
-wl,option : 將選項(option)傳給連結器
-I : 追加include檔案的搜尋路徑
-L : 追加library檔案的搜尋路徑
-l : 指定連結的函式庫
-Wall : 顯示所有的警告訊息
-g : 編入除錯資訊(要使用GDB除錯一定要加)
-O2 : 做最佳化

Reference: http://www.wretch.cc/blog/Geniusking/7263728

}}}


Simple Link:
{{{
http://linux.vbird.org/
}}}



沒有留言:

張貼留言