GCC - the GNU Compiler Collection

Cài đặt

  • Trên Mac: cài đặt xcode command line tools
    • Mở terminal
    • Gọi lệnh xcode-select –install
    • Kiểm tra cài đặt
      • Gọi lệnh: xcode-select -p thì kết quả là: /Library/Developer/CommandLineTools
      • Gọi lệnh: gcc –version thì kết quả … Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn) …
  • Trên windows
    • Cách 1
      • Download MinGW tại đường link http://sourceforge.net/projects/mingw/files/
      • Cài đặt và được kết quả
      • Chuột phải vào gcc cho C++ => menu File => chọn Apply changes
    • Cách 2
      • Truy cập http://mingw-w64.sourceforge.net/
      • Tải gcc phiên bản mới nhất
      • Giải nén vào thư mục C:\abc\gcc-4.9-win64
      • Thêm C:\abc\gcc-4.9-win64\bin vào biến PATH

Sử dụng

  • Viết code cho chương trình hello như sau
1
2
3
4
5
6
7
8
//Tap tin program1.cpp
#include <iostream>
using namespace std;

int main()
{
	cout << "Hello world ..." << endl;
}
  • Biên dịch bằng lệnh sau
1
g++ -o hello.exe program1.cpp
  • Chạy chương trình hello.exe ta được kết quả Hello world …

Tài liệu tham khảo

  • Giới thiệu: https://gcc.gnu.org/
  • Cài đặt windows: http://stackoverflow.com/questions/6394755/how-to-install-gcc-on-windows-7-machine
  • Cài đặt mac: https://solarianprogrammer.com/2013/06/11/compiling-gcc-mac-os-x/
  • Cài đặt mac: http://railsapps.github.io/xcode-command-line-tools.html
  • Sử dụng: http://pages.cs.wisc.edu/~beechung/ref/gcc-intro.html