A short documentation on how to setup, compile and run C++ properly on Linux.
Have build-essential installed
sudo apt update && sudo apt install build-essentialThis installs necessary packages such as g++ for compiling C++ source files.
Run build.sh to compile main.cpp into a Linux executable main
Note: You will need a cross compiler to compile for other platforms, such as using
mingw-w64to compile for Windows. Another option would be to compile directly on the target machine.
Option 1:
bash build.shOption 2:
- First give execute permissions
chmod +x build.sh- Then run the script
./build.shThe bash script is written because i dun wanna type so many characters everytime i wanna build lol. Also prevents typos. I also dun needa remember all the commands if i just needa remember bash build.sh. Also allows the build step to change while i just needa remember one command.
But yeah, at least at this stage u can just build directly using
g++ main.cpp -o mainRun
./mainYou should see the following output:
Hello World!