gcc = GNU C Compiler, g++ = GNU C++ Compiler
ความแตกต่างหลัก
| พฤติกรรม | gcc | g++ |
|---|---|---|
| .c files | Compile as C | Compile as C++ |
| .cpp files | Compile as C++ | Compile as C++ |
| Linking | ไม่ link libstdc++ อัตโนมัติ | Link libstdc++ อัตโนมัติ |
| Predefined macros | น้อยกว่า (C) | มากกว่า (C++ macros) |
Macros เพิ่มเติมของ C++ (g++ และ gcc กับ .cpp)
#define __GXX_WEAK__ 1 #define __cplusplus 1 #define __DEPRECATED 1 #define __GNUG__ 4 #define __EXCEPTIONS 1 #define __private_extern__ extern
แนวทางใช้งาน
- โค้ด C ใช้
gcc - โค้ด C++ ใช้
g++(ง่ายกว่า ไม่ต้องเพิ่ม -lstdc++) - โปรเจคผสม: ใช้ g++ คอมไพล์ทั้งหมด หรือ gcc กับ -lstdc++