A command-line tool to compile and run C/C++ files with a single command.
🇧🇷 Portuguese Version (Versão em Português)
CExec is a lightweight Go tool crafted to streamline the compilation and execution of C/C++ programs. With just one terminal command, it automates the entire process, making it effortless for developers to test and run their code. Designed for efficiency, CExec simplifies workflows by combining both steps into a single, intuitive action.
The traditional way requires multiple commands to compile and then run C/C++ programs:
With CExec, the entire process is simplified into a single command:
Boost your productivity with the powerful Watch Mode! 🚀
CExec's Watch Mode completely transforms your C/C++ development experience. With it enabled, you can:
- Forget repetitive commands - while you write code, CExec watches your changes and automatically recompiles.
- See results instantly - every time you save a file, your code is recompiled and run immediately.
- Focus on what really matters: your code - no more switching between editor and terminal!
It's like having a programming assistant that runs your code whenever you make a change. Perfect for:
- Iterative and incremental development
- Learning C/C++
- Quick debugging
- Instant testing of small changes
CExec -watch=true my_program.cppThat's it! Now you can edit your file with peace of mind - with each save, CExec will automatically recompile and run your program, displaying the results in the terminal.
- Go (to build from source)
- A C/C++ compiler (such as g++)
- Clone this repository
- Compile the program:
go build -o build/CExec src/main.go- Add the compiled executable to your PATH for global usage (optional)
CExec file.(c/cpp)The program will:
- Compile the specified C/C++ file using the configured compiler
- Run the resulting program (if configured)
- Display the program output
You can also use command-line flags to customize CExec's behavior:
CExec -compiler=/path/to/g++ -args="-Wall,-std=c++17" -output=my_program -run=true -source=main.cpp -watch=true| Flag | Description | Default |
|---|---|---|
-compiler |
Path to the compiler | From config file or required |
-args |
Compiler arguments (comma-separated) | From config file or none |
-output |
Name of the output executable | "output" or "output.exe" (Windows) |
-run |
Whether to run the program after compilation | From config file or false |
-run-cmd |
Custom arguments to pass to the program when running | From config file or none |
-source |
Source file to compile | From config file or required |
-watch |
Enable file watching mode to recompile on changes | From config file or false |
CExec offers two flexible configuration methods:
You can create a CExecConfig.json file in your working directory for permanent configurations:
{
"compilerPath": "/usr/bin/g++",
"compilerArgs": ["-Wall", "-std=c++17"],
"outputName": "my_program",
"runAfterCompile": true,
"customRunCommand": "arg1 arg2",
"sourceFile": "main.cpp",
"watchChanges": false
}For quick usage or to override JSON file configurations, use command-line flags:
CExec -compiler=/path/to/g++ -args="-Wall,-std=c++17" -output=my_program -run=true -source=main.cpp -watch=trueCExec follows a clear order to determine which configuration to use:
- Command-line flags (highest priority) - override any other configuration
- CExecConfig.json file (medium priority) - used when flags are not present
- Default values (lowest priority) - used when no other configuration is provided
This allows you to have a configuration file for your default values, while maintaining flexibility for quick overrides via command line when needed.
| Option | Description | Related Flag | JSON Config | Required |
|---|---|---|---|---|
| Compiler path | Path to the compiler (e.g., g++) | -compiler |
compilerPath |
Yes |
| Compiler arguments | List of arguments for the compiler | -args |
compilerArgs |
No |
| Executable name | Name of the generated executable file | -output |
outputName |
No (default: "output" or "output.exe" on Windows) |
| Run after compilation | Whether to execute the program after compilation | -run |
runAfterCompile |
No (default: false) |
| Run arguments | Arguments to pass to the program during execution | -run-cmd |
customRunCommand |
No |
| Source file | Source file to be compiled | -source |
sourceFile |
No (can be specified as first argument) |
| Watch mode | Enable file watching mode to recompile on changes | -watch |
watchChanges |
No (default: false) |
$ CExec my_program.cppIf the program my_program.cpp contains:
#include <iostream>
int main() {
std::cout << "Hello, world!" << std::endl;
return 0;
}The output will be:
Hello, world!
$ CExec -watch=true my_program.cppThis will start CExec in watch mode. It will compile the file, and then continue monitoring it for changes. Whenever the file is modified and saved, CExec will automatically recompile it.
The executable automatically detects the operating system and adjusts the output file name:
- On Linux/Unix systems:
output - On Windows systems:
output.exe
Contributions are welcome! Feel free to open issues or submit pull requests.

