여기서는 C++ 프로그램에서 여러 cpp 파일을 컴파일하는 방법을 살펴보겠습니다. 작업은 매우 간단합니다. 이름을 g++ 컴파일러에 목록으로 제공하여 하나의 실행 파일로 컴파일할 수 있습니다.
abc.cpp 및 xyz.cpp와 같은 여러 파일을 한 번에 컴파일하려면 구문은 다음과 같습니다. -
g++ abc.cpp xyz.cpp
프로그램을 실행하기 위해 다음을 사용할 수 있습니다 -
./a.out
예시
float area(float r){
return (3.1415*r*r); //area of a circle
}
float area(float l, float w) {
return (l * w); //area of a rectangle
} 예시
#include <iostream>
#include "area.cpp"
using namespace std;
main() {
cout << "Area of circle with radius 2.5 is: " << area(2.5) << endl;
cout << "Area of rectangle with length and width are 5 and 7 is: " << area(5, 7) << endl;
} 출력
$ g++ area.cpp find_area.cpp $ ./a.out Area of circle with radius 2.5 is: 19.6344 Area of rectangle with length and width are 5 and 7 is: 35 $