Skip to content

Build Commands

Building a project is done by invoking the C3 compiler with the build or run command inside of the project structure. The compiler will search upwards in the file hierarchy until a project.json file is found.

You can also customise the project build config.

By default the compiler is compiling stand-alone files to output an executable binary.

Terminal window
c3c compile <file1> <file2> <file3>

When starting out, with C3 it’s natural to use compile-run to try things out. For larger projects, the built-in build system is recommended instead.

The compile-run command works same as compilation, but also immediately runs the resulting executable.

Terminal window
c3c compile-run <file1> <file2> <file3>

Additional parameters:

  • --lib <path> add a library to search.
  • --output <path> override the output directory.
  • --path <path> execute as if standing at <path>
Terminal window
c3c init <project_name> [optional path]

Create a new project structure in the current directory.

Use the --template to select a template. The following are built in:

  • exe - the default template, produces an executable.
  • static-lib - template for producing a static library.
  • dynamic-lib - template for producing a dynamic library.

It is also possible to give the path to a custom template.

Additional parameters:

  • --template <path> indicate an alternative template to use.

For example c3c init hello_world creates the following structure:

  • Directorybuild/
  • Directorydocs/
  • Directorylib/
  • Directoryresources/
  • Directoryscripts/
  • Directorysrc/
    • main.c3
  • Directorytest/
  • LICENSE
  • project.json
  • README.md

Check the project configuration docs to learn more about configuring your project.

Terminal window
c3c test

Will run any tests in the project in the "sources" directory defined in your project.json for example:

...
"sources": [ "src/**" ],
...

Tests are defined with a @test attribute, for example:

fn void test_fn() @test
{
assert(true == true, "true is definitely true");
}
Terminal window
c3c build [target]

Build the project in the current path. It doesn’t matter where in the project structure you are.

The built-in templates define two targets: debug (which is the default) and release.

Terminal window
c3c clean
Terminal window
c3c run [target]

Build the target (if needed) and run the executable.

Terminal window
c3c clean-run [target]

Clean, build and run the target.

Terminal window
c3c dist [target]

Not properly added yet

Clean, build and package the target for distribution. Will also run the target if it is a executable.

Terminal window
c3c docs [target]

Not added yet

Rebuilds the documentation.

Terminal window
c3c bench [target]

Runs benchmarks on a target.