This project generates a template C project with CMake and Make build systems. It provides a quick and easy way to scaffold a new C project with a basic directory structure, build files, and a "Hello, world!" example.
You can install cnew
to easily generate new C projects with CMake and Make build systems by running the following command:
cargo install --git https://github.com/jgsn13/cnew
This will download and install the cnew
binary to your system's PATH
(usually ~/.cargo/bin
).
Note: This requires Rust and Cargo to be installed beforehand. You can install them from the official website: https://www.rust-lang.org/tools/install.
After installing cnew
, you can generate a new C project by running the following command in your terminal:
cnew project_name
Replace project_name
with the desired name for your new project. This will create a new directory with the specified name and populate it with the template project files.
The generated project has the following directory structure:
project\_name/
├── CMakeLists.txt
├── src/
│ └── main.c
├── Makefile
├── README.md
└── .gitignore
CMakeLists.txt
: Configures the CMake build system for your project.src/
: Contains all source code files, currently justmain.c
.Makefile
: Defines build targets for compiling, running, cleaning, and testing.README.md
: This file provides information about the generated project..gitignore
: Specifies files to be ignored by Git version control.
The generated project uses CMake and Make for building. You'll need these tools installed on your system.
- Navigate to the generated project directory:
cd project_name
- Build the project:
make
This will create the executable file named project_name
in the current directory.
- Run the built executable:
./project_name
This will print "Hello, world!" to the console.
A convenient target is available to compile, run, and clean the project in one go:
make test
Clean the project and remove any generated files:
make clean
GNU AFFERO GENERAL PUBLIC LICENSE
- Joaquim Gregório da Silva Neto joaquim.ibi@gmail.com