cppargo
is a tool to mimic the basic functionalities of the cargo
utility
for Rust projects but for C++ projects.
Currently, cppargo
is hard-coded to use g++
as the compiler for the C++
projects it manages. So ensure that you have it installed. Most Unix systems
have it already installed. Installation instructions for g++
can be found
on the website, or with your system's package manager. g++
is not required
to install cppargo
, but it is currently indispensible to compile C++
projects.
sudo dnf install gcc-c++
sudo apt install gcc
sudo pacman -S gcc
brew install gcc
Installation can currently only be done using cargo
, the Rust project
management tool this project aims to emulate. If you haven't already installled
Rust, follow the installation instructions from their website on how to
install utilizing rustup
.
From crates.io
cargo install cppargo
cargo install --git https://www.github.com/bassedwarrior/cppargo
-
Clone the repo locally.
- Using
gh
(GitHub's CLI Tool).
gh repo clone BassedWarrior/cppargo
- Using
git
git clone https://www.github.com/bassedwarrior/cppargo
- Using
-
From inside the cloned repo, compile the binary.
cargo install --path .
- Create a new project at any
PATH
and move to thatPATH
.
cppargo new <PATH>
cd <PATH>
- Run the sample hello world program automatically created by
cppargo
.
cppargo run
-
Edit the main
src/main.cpp
file as desired. -
Build or build and run the new project.
-
Build
cppargo build
-
Build and run
cppargo run
-
-
Build, but run manually.
-
Build
cppargo build
-
Run manually
./target/<PROJECT-NAME>
-
In order to create a new project, use the command
cppargo new <PATH>
This will create a new directory at PATH
. Relative or absolute paths are
accepted, and will be created accordingly. This directory will be considered
the root of the cppargo
project.
Inside the project root directory, cppargo
will also create a Cppargo.toml
manifest file akin to a Cargo.toml
file used by cargo
. Internally,
cppargo
looks for such a file to determine the project root, or determine
that it is not within a cppargo
project.
And finally, cppargo
will create a src
directory with a basic
src/main.cpp
"Hello World!" C++ program. This is the directory where all of
the source files for the project should be included.
From inside a cppargo
project, in order to build a project, use the command
cppargo build
Firstly, cppargo
will look for a Cppargo.toml
manifest file in the current
directory. If it doesn't find one, then it will check the parent directory's
contents recursively for it. If it fails to find a Cppargo.toml
file, then it
exits with an error due to not being inside a cppargo
project, as the
Cppargo.toml
determines the root of any cppargo
project.
From the project root, it will look for the PROJECT_ROOT/src
directory to
find all of the .cpp
files insde it. The file structure inside the src
directory is irrelevant to cppargo
, since it will search exhaustively all
subdirectories to find all .cpp
files.
Once gathered, all of the .cpp
files are sent as arguments to g++
to be compiled. This means that cppargo
does no linkage or compilation of its
own, nor does it check for any bad #include
statements, or the lack thereof.
The compiled excecutable file is then stored within a PROJECT_ROOT/target
directory. cppargo
first checks to ensure that the directory exists, and
creates it if it doesn't exist. The excecutable file's name is gathered from
the project manifest by reading the project's name. The compiled excecutable is
then placed at PROJECT_ROOT/target/PROJECT_NAME
.
From inside a cppargo
project, in order to run a project, use the command
cppargo run
This will first perform a cppargo build
and then run the
PROJECT_ROOT/target/PATH
file generated after a successful compilation. The
proper working directory for the excecutable will be the same as the one
cppargo
was excecuted in. This should be kept in mind when the program
expects a certain file structure or a certain working directory.