Cú pháp: g++ file1.cpp file2.cpp ... → tạo a.out. Chạy: ./a.out.
Ví dụ
area.cpp
float area(float r) { return 3.1415f * r * r; }
float area(float l, float w) { return l * w; }find_area.cpp
#include <iostream>
#include "area.cpp" // hoặc area.h
using namespace std;
int main() {
cout << area(2.5) << endl;
cout << area(5, 7) << endl;
}Biên dịch & chạy
$ g++ area.cpp find_area.cpp $ ./a.out 19.6344 35