https://github.com/agentcooper/cpp-makefile-example
Example Makefile for a C++ project with incremental compilation and automatic resolution of dependencies (header files)
https://github.com/agentcooper/cpp-makefile-example
cpp makefile
Last synced: 8 days ago
JSON representation
Example Makefile for a C++ project with incremental compilation and automatic resolution of dependencies (header files)
- Host: GitHub
- URL: https://github.com/agentcooper/cpp-makefile-example
- Owner: agentcooper
- Created: 2023-10-12T14:22:11.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-12T14:26:49.000Z (over 2 years ago)
- Last Synced: 2025-03-02T18:28:38.429Z (over 1 year ago)
- Topics: cpp, makefile
- Language: Makefile
- Homepage:
- Size: 1000 Bytes
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Example Makefile for a C++ project with incremental compilation and automatic resolution of dependencies (header files).
## Demo
Initial compilation:
```bash
% make
g++ -Wall -std=c++20 -MMD -c src/A.cpp -o build/A.o
g++ -Wall -std=c++20 -MMD -c src/B.cpp -o build/B.o
g++ -Wall -std=c++20 -MMD -c src/main.cpp -o build/main.o
g++ -Wall -std=c++20 -MMD -o main build/A.o build/B.o build/main.o
```
Edit header dependency:
```bash
sed -i '' 's/John/Jane/' src/C.hpp
```
Only B module is rebuilt on recompilation:
```bash
% make
g++ -Wall -std=c++20 -MMD -c src/B.cpp -o build/B.o
g++ -Wall -std=c++20 -MMD -o main build/A.o build/B.o build/main.o
```