gcc & g++

The actual compiler is "cc1" for C and "cc1plus" for C++; both gcc and g++ are drivers (which call the preprocessor/compiler/assembler/linker as needed). – CesarB

original link:  http://thatax.blog.163.com/blog/static/208926802008625111552124/

GCC stands for “GNU Compiler Collection”. GCC is an integrated distribution of compilers for several major programming languages. These languages currently include C, C++, Objective-C, Objective-C++, Java, Fortran, and Ada.

g++ is a program that calls GCC with the default language set to C++, and automatically specifies linking against the C++ library. On many systems, g++ is also installed with the name c++.

 

gcc和g++都是GNU(組織)的一個編譯器。

誤區一:gcc只能編譯c代碼,g++只能編譯c++代碼

兩者都可以,但是請注意:

1.後綴爲.c的,gcc把它當作是C程序,而g++當作是c++程序;後綴爲.cpp的,兩者都會認爲是c++程序,注意,雖然c++是c的超集,但是兩者對語法的要求是有區別的。C++的語法規則更加嚴謹一些。

2.編譯階段,g++會調用gcc,對於c++代碼,兩者是等價的,但是因爲gcc命令不能自動和C++程序使用的庫聯接,所以通常用g++來完成鏈接,爲了統一起見,乾脆編譯/鏈接統統用g++了,這就給人一種錯覺,好像cpp程序只能用g++似的。

 

誤區二:gcc不會定義__cplusplus宏,而g++會

實際上,這個宏只是標誌着編譯器將會把代碼按C還是C++語法來解釋,如上所述,如果後綴爲.c,並且採用gcc編譯器,則該宏就是未定義的,否則,就是已定義。

 

誤區三:編譯只能用gcc,鏈接只能用g++

嚴格來說,這句話不算錯誤,但是它混淆了概念,應該這樣說:編譯可以用gcc/g++,而鏈接可以用g++或者gcc -lstdc++。因爲gcc命令不能自動和C++程序使用的庫聯接,所以通常使用g++來完成聯接。但在編譯階段,g++會自動調用gcc,二者等價。

文章引用自:http://community.csdn.net/Expert/topic/5173/5173006.xml?temp=.5406153


reference: http://stackoverflow.com/questions/172587/what-is-the-difference-between-g-and-gcc
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章