https://github.com/gjtiquia/hello-world-cpp
A short documentation on how to setup, compile and run C++ properly on Linux.
https://github.com/gjtiquia/hello-world-cpp
cpp linux
Last synced: 3 months ago
JSON representation
A short documentation on how to setup, compile and run C++ properly on Linux.
- Host: GitHub
- URL: https://github.com/gjtiquia/hello-world-cpp
- Owner: gjtiquia
- Created: 2024-12-02T21:14:27.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-02T23:40:01.000Z (over 1 year ago)
- Last Synced: 2026-01-01T10:42:49.984Z (6 months ago)
- Topics: cpp, linux
- Language: Shell
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Hello World C++
A short documentation on how to setup, compile and run C++ properly on Linux.
## Prerequisites
Have `build-essential` installed
```bash
sudo apt update && sudo apt install build-essential
```
This installs necessary packages such as `g++` for compiling C++ source files.
## Build - Using bash script
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-w64` to compile for Windows. Another option would be to compile directly on the target machine.
Option 1:
```bash
bash build.sh
```
Option 2:
- First give execute permissions
```bash
chmod +x build.sh
```
- Then run the script
```bash
./build.sh
```
## Build - Using g++
The 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
```bash
g++ main.cpp -o main
```
## Execute
Run
```bash
./main
```
You should see the following output:
```txt
Hello World!
```