An open API service indexing awesome lists of open source software.

https://github.com/yuvrajkarna2717/cpp_setup

A setup designed to help write code faster during programming contests.
https://github.com/yuvrajkarna2717/cpp_setup

competitive-programming-contests cpp

Last synced: 11 months ago
JSON representation

A setup designed to help write code faster during programming contests.

Awesome Lists containing this project

README

          

## πŸ’» Requirements

Before you begin, ensure you have the following tools installed:

### πŸ”Ή For Windows (using MSYS2 - Recommended)
1. Download & install [**MSYS2**](https://www.msys2.org/)
2. Launch the **MSYS2 MinGW 64-bit** shell
3. Run the following commands:

```bash
pacman -Syu # Update MSYS2 packages (restart if needed)
pacman -S mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake
````

This installs:

* `g++` compiler
* `make`
* `cmake`

> ⚠️ Make sure you're using the `MINGW64` shell (`mingw64.exe`), **not** the `MSYS` or `UCRT` ones.

## πŸ›  Setup & Build Instructions (Highly Detailed)

These steps will guide you from cloning the repo to compiling and running your project on any machine.

### βœ… Step 1: Clone the Repository

```bash
git clone https://github.com/yuvrajkarna2717/cpp_setup.git
cd cpp_setup
```

### βœ… Step 2: Create the Build Directory

CMake prefers out-of-source builds (keeps things clean):

```bash
mkdir build
cd build
```

### βœ… Step 3: Run CMake to Generate Build Files

```bash
cmake ..
```

* This scans `CMakeLists.txt`, checks for your compiler, and prepares a build system.
* It will fail if `cmake` or `g++` are not installed.

### βœ… Step 4: Build the Project

```bash
cmake --build .
```

* Compiles `main.cpp` into an executable (e.g., `main.exe` on Windows)
* Incremental: Only recompiles changed files.

### βœ… Step 5: Run the Executable

```bash
./main.exe # Windows
./main # macOS/Linux
```

---

## πŸš€ Quick Rebuild & Run Using `run.sh`

Instead of running commands manually every time, you can use the helper script:

### πŸ“„ `run.sh` Contents

```bash
#!/bin/bash
cd build || exit
cmake --build .
echo -e "\n--- Running ---\n"
./main.exe
```

### ▢️ How to Use It

1. Make it executable (only once):

```bash
chmod +x run.sh
```

2. Run the full compile + execute process:

```bash
./run.sh
```

> πŸ“ This script assumes you already have a `build/` directory and it’s configured via `cmake ..`. If not, run steps 2 & 3 first.

---

## πŸ” What to Do After Code Changes?

| Change Type | What You Run |
| ------------------------ | --------------------------------------------- |
| `.cpp` or `.h` modified | `cmake --build . && ./main.exe` or `./run.sh` |
| New file / renamed file | `cmake .. && cmake --build . && ./main.exe` |
| `CMakeLists.txt` changed | `cmake ..` again before building |

---

## πŸ“‚ Project Structure

```
cpp_setup/
β”œβ”€β”€ CMakeLists.txt # CMake configuration
β”œβ”€β”€ main.cpp # Entry point
β”œβ”€β”€ run.sh # Automate build + run
└── build/ # (Generated) build files & executable
```

---

## πŸ“œ License

MIT License β€” free to use, modify, and distribute.

---

## πŸ‘¨β€πŸ’» Author

[Yuvraj Karna](https://github.com/yuvrajkarna2717)

---

## 🌟 Support

If this project helps you, please consider ⭐ starring the repo to show your support!