gcc,g++
什麼是gcc / g++
首先說明:gcc 和 GCC 是兩個不同的東西
GCC:GNU Compiler Collection(GUN 編譯器集合),它可以編譯C、C++、JAV、Fortran、Pascal、Object-C、Ada等語言。
gcc是GCC中的GUN C Compiler(C 編譯器)
g++是GCC中的GUN C++ Compiler(C++編譯器)
一個有趣的事實就是,就本質而言,gcc和g++並不是編譯器,也不是編譯器的集合,它們只是一種驅動器,根據引數中要編譯的檔案的型別,呼叫對應的GUN編譯器而已,比如,用gcc編譯一個c檔案的話,會有以下幾個步驟:
Step1:Call a preprocessor, like cpp.
Step2:Call an actual compiler, like cc or cc1.
Step3:Call an assembler, like as.
Step4:Call a linker, like ld
由於編譯器是可以更換的,所以gcc不僅僅可以編譯C檔案
所以,更準確的說法是:gcc呼叫了C compiler,而g++呼叫了C++ compiler
gcc和g++的主要區別
1. 對於 *.c和*.cpp檔案,gcc分別當做c和cpp檔案編譯(c和cpp的語法強度是不一樣的)
2. 對於 *.c和*.cpp檔案,g++則統一當做cpp檔案編譯
3. 使用g++編譯檔案時,g++會自動連結標準庫STL,而gcc不會自動連結STL
4. gcc在編譯C檔案時,可使用的預定義巨集是比較少的
5. gcc在編譯cpp檔案時/g++在編譯c檔案和cpp檔案時(這時候gcc和g++呼叫的都是cpp檔案的編譯器),會加入一些額外的巨集,這些巨集如下:
#define __GXX_WEAK__ 1
#define __cplusplus 1
#define __DEPRECATED 1
#define __GNUG__ 4
#define __EXCEPTIONS 1
#define __private_extern__ extern
6. 在用gcc編譯c++檔案時,為了能夠使用STL,需要加引數 –lstdc++ ,但這並不代表 gcc –lstdc++ 和 g++等價,它們的區別不僅僅是這個
主要引數
-g - turn on debugging (so GDB gives morefriendly output)
-Wall - turns on most warnings
-O or -O2 - turn on optimizations
-o - name of the output file
-c - output an object file (.o)
-I - specify an includedirectory
-L - specify a libdirectory
-l - link with librarylib.a
轉:https://www.cnblogs.com/oxspirt/p/6847438.html