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.
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
Directory | Usage |
---|---|
./build | Where your temporary files and build results will go. |
./docs | Code Documentation |
./lib | C3 libraries (with the .c3l suffix) |
./resources | Non-code resources like images, sound effects etc. |
./scripts | Scripts, including .c3 scripts that generate code at compile time. |
./src | Storing our code, by default contains main.c3 with βHello Worldβ. |
project.json | Record project information, similar to package.json in NodeJS. |
LICENSE | Project license. |
README.md | Help 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.
You can also specify the target to build & run.
π§ Build
If you only want to build the project, you can use the build
command:
This command builds the project targets defined in our project.json
file.
We will now have a binary in build
, which we can run:
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.