Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C++

MakeFile trong C++ và ứng dụng


Trong hướng dẫn này, ta thảo luận về MakeFile trong C++ và ứng dụng.

Nhiệm vụ là tách chương trình thành nhiều file .cpp và .h, sau đó dùng MakeFile để liên kết chúng lại.

Ví dụ

main.cpp

#include <bits/stdc++.h> #include "function.h" using namespace std; int main(){ int num1 = 1, num2 = 2; cout << multiply(num1, num2) << endl; int num3 = 5; cout << factorial(num3) << endl; print(); }

print.cpp

#include <bits/stdc++.h> #include "function.h" using namespace std; void print() { cout << "makefile" << endl; }

factorial.cpp

#include <bits/stdc++.h> #include "function.h" using namespace std; int factorial(int n){ if (n == 1) return 1; return n * factorial(n - 1); }

multiply.cpp

#include <bits/stdc++.h> #include "function.h" using namespace std; int multiply(int a, int b){ return a * b; }

functions.h

#ifndef FUNCTIONS_H #define FUNCTIONS_H void print(); int factorial(int); int multiply(int, int); #endif

Đầu ra

2 120 makefile