Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C++

ความแตกต่างระหว่าง GCC และ G++ Compilers

gcc = GNU C Compiler, g++ = GNU C++ Compiler

ความแตกต่างหลัก

พฤติกรรมgccg++
.c filesCompile as CCompile as C++
.cpp filesCompile 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++