cw is a simple CLI tool that automatically compiles and runs C/C++ files whenever they are modified, saving you time and effort.
To install cw globally using npm, run:
npm install -g c_cpp-watcherPrerequisites:
Make sure you have a C/C++ compiler installed (gcc for C, g++ for C++). You can check by running:
gcc --version
g++ --versioncw [options] <file...> [compiler flags] [-- program arguments]
cw main.cpp # watch, compile and run
cw main.cpp -Wall -std=c++17 # pass flags to the compiler
cw main.cpp util.cpp -I include # compile several files together
cw main.c -- --input data.txt # pass arguments to your program
cw --compiler clang++ main.cpp # use a different compilerEverything between the source files and -- goes to the compiler. Everything
after -- goes to your program, so a flag like --verbose reaches your argv
instead of being handed to the compiler.
- The program recompiles and restarts whenever a watched file changes.
- Headers are watched too.
cwasks the compiler which headers your sources include, so editingutils.hrebuildsmain.cpp. - When the program isn't running, type
rsto restart it orqto quit. - Each build reports how long it took, and each run reports the exit code.
cw's own options go before the source files, so they can never be mistaken for
a compiler flag like -w or -v.
| Option | Description |
|---|---|
-h, --help |
Show usage |
--version |
Show the version |
--compiler <bin> |
Compiler to use (defaults to g++/gcc, or $CXX/$CC) |
--out <path> |
Executable to write (-o among the compiler flags works too) |
--watch <path> |
Also watch this file or directory, repeatable |
--no-run |
Compile on change without running |
--clear |
Clear the screen before each rebuild |