Skip to content

Projects

Projects in C3

Projects are optional, but are a good way to manage compiling code when there are a lot of files and modules. They also allow you to specify libraries to link, and define how your project should be built for specific targets.

πŸ’‘ Creating a new project

The c3c init command will create a new directory containing your project structure. It requires a name of the project, we will use myc3project in its place.

Terminal window
c3c init myc3project

You can also customize the path where the project will be created or specify a template. For more information check the init command reference.

πŸ“ Project structure

If you check the directory that was created you might find it a bit confusing with a bunch of different directories, but worry not because if you expand them you will realise that most of them are actually empty!

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

Directory Overview

DirectoryUsage
./buildWhere your temporary files and build results will go.
./docsCode Documentation
./libC3 libraries (with the .c3l suffix)
./resourcesNon-code esources like images, sound effects etc.
./scriptsScripts, including .c3 scripts that generate code at compile time.
./srcStoring our code, by default contains main.c3 with β€œHello World”.
project.jsonRecord project information, similar to package.json in NodeJS.
LICENSEProject license.
README.mdHelp others understand and use your code.

πŸ”§ Building the project

Assuming you have successfully initialized a project as seen above, we can now look at how to compile it.

πŸƒ Build & run

C3 has a simple command to build & run our project.

Terminal window
c3c run
> Program linked to executable 'build/myc3project'.
> Launching ./build/myc3project...
> Hello, World

You can also specify the target to build & run.

Terminal window
c3c run myc3project

πŸ”§ Build

If you only want to build the project, you can use the build command:

Terminal window
c3c build

This command builds the project targets defined in our project.json file.

We will now have a binary in build, which we can run:

Terminal window
./build/myc3project

It should print Hello, World! and return back to the command line prompt. If you are on Windows, you will have myc3project.exe instead. Call it in the same way.

If you need more detail later on check C3 project build commands and C3 project configuration to learn more.