यहां हम देखेंगे कि 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 $