A smart script to automate C++ compilation β only recompiles when the source code changes.
- Saves time and resources by reducing unnecessary compilations.
- Only recompiles when the source file changes.
- Displays clear success or error messages.
- Clone the repository:
git clone https://github.com/AbdoViper23/Smart-Compile.git
- Navigate to the script folder:
cd Smart-Compile - Make the script executable:
chmod +x smart-compile.sh
- Ensure
g++is installed:sudo apt install g++
To compile a C++ file:
./smart-compile.sh <filename.cpp>Example:
./smart-compile.sh main.cpp- Install the Code Runner extension from the VS Code marketplace.
- Open VS Code and open Settings (
Ctrl + ,) or go toFile > Preferences > Settings. - Search for
code-runner.executorMapand click on Edit in settings.json. - Make sure to move the script file (
smart-compile.sh) to the same directory as your C++ file OR place it in the~/bindirectory, then add its path to thePATHusing the command:
If it's in the same folder, you don't need to add it to
~/binandPATH.
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc- change the "CPP" configuration to use the script with C++ files:
"code-runner.executorMap": { "cpp": "bash ./smart-compile.sh $fileName" }
- Enable Code Runner to run in the terminal:
- Open Settings (
Ctrl + ,) - Search for
code-runner.runInTerminal - Check the option β "Code-runner: Run in Terminal"
- Open Settings (
- Save the file.
- To run a C++ file using Code Runner, open the file and press
Ctrl + Alt + Nor click the Run button.
Successful compilation:
####################
# Compilation Done #
####################
Compilation error:
#####################
# Compilation Error #
#####################
- Fork the repo.
- Create a new branch:
git checkout -b feature/new-feature
- Make your changes and commit:
git commit -m "Add new feature" - Push to your branch:
git push origin feature/new-feature
- Create a Pull Request.