![]() |
Flecs v4.1
A fast entity component system (ECS) for C & C++
|
This manual describes how to compile the Flecs source code.
The following libraries need to be linked when building Flecs:
Windows
| Library | Used by | Used for |
|---|---|---|
| dbghelp | Core | Logging stack traces |
| ws2_32 | HTTP addon | Allows explorer to connect |
Linux
| Library | Used by | Used for |
|---|---|---|
| rt | Core | Time functions |
| pthread | OS_API addon | Threading functions |
| m | Core | Math functions |
MacOS
No dependencies required on MacOS.
The easiest way to add Flecs to a project is to add the distr/flecs.c and distr/flecs.h files to the project source. When building, make sure your build system is setup to do the following:
gcc/clang instead of g++/clang++.-lws2_32 -ldbghelp to the end of the linker command.gcc/clang, add -std=gnu99 to the compiler command. This ensures that addons that rely on time & socket functions are compiled correctly.-std=c++17 or higher.These examples are just for illustration. For most projects it is recommended to use a build system like cmake, bazel or bake.
Windows
Clang, C
Clang, C++
MSVC, C
MSVC, C++
Linux
GCC, C
GCC, C++
Clang, C
Clang, C++
Macos
Clang, C
Clang, C++
To build the distr/flecs.c and distr/flecs.h files as a shared library, remove this line from the top of flecs.h:
When compiling distr/flecs.c, make sure to define flecs_EXPORTS, for example by adding -Dflecs_EXPORTS to the compiler command. This ensures that Flecs symbols are exported.
The following example shows how to create a shared library using flecs.c and flecs.h with clang on Linux:
If you've made a modification to the Flecs source code (in the src or include folders) and you want to update the flecs.c and flecs.h files in the distr folder, run bake once in the root of the repository:
Make sure that the files in distr now have your modifications. If they have not been updated, it's possible that the date of the files is newer than your modifications. If this happens, remove the distr folder and run bake again. This will regenerate files with the latest modifications.
It is not recommended to modify the flecs.c and flecs.h directly.
This will build the files in src and include with one of the following build systems:
Run this command in the repository root to create flecs library binaries:
After the command finishes, the cmake_build folder will contain one static and one dynamic library binary.
You can also add the Flecs repository as dependency for another cmake project by adding the following line to the CMakeLists.txt of the project:
Alternatively, you can use FetchContent to automatically download Flecs:
Then to link with flecs, add the following to CMakeLists.txt:
To build Flecs with meson, run the following commands in the repository root:
To build Flecs with bazel, run the following command in the repository root:
To build Flecs with bake, run the following command in the repository root:
After this Flecs should show up in the bake environment when doing:
To create a new Flecs C project, do:
To create a new Flecs C++ project, do:
To run the project, do:
To generate the HTML version of the documentation, run the following command:
The generated HTML files will be written to docs/html.
Flecs uses the test framework that ships with bake. While it is possible to run tests with other build systems, it is recommended to use bake.
Make sure to at least build flecs once, by running this in the repository root:
Make sure that Flecs is listed in the bake environment by doing:
Then run the command for the test project you want to run:
To run a single test suite, do:
To run a single test case, do:
Some test suites are parameterized. To provide a value for a parameter, do:
You can specify the number of threads with -j (default is 4):
To add a new test case, first add it to the project.json of the project you want to add it to, for example:
Then build the test project once:
The suite to which you added the test case will now have an empty test function:
When running the test suite now you will see:
This indicates that the test case isn't testing anything yet. Add one or more test_assert (or equivalent) calls to the code to make this message go away.
First make sure to clone bake.
Run the following commands to run all the tests:
Run the following commands to run all the tests:
When building for emscripten, add the following command line options to the emcc link command:
When building for Android, you should:
cacheVariables as you likeThen run command ninja in build_android directory to start build.
Flecs has a modular architecture that makes it easy to only build the features you really need. By default all addons are built. To customize a build, first define FLECS_CUSTOM_BUILD, then add defines for the addons you need. For example:
Additionally, you can also specify addons to exclude from a build by adding NO to the define:
The following addons can be configured:
| Addon | Description | Define |
|---|---|---|
| Cpp | C++17 API | FLECS_CPP |
| Module | Organize game logic into reusable modules | FLECS_MODULE |
| System | Create & run systems | FLECS_SYSTEM |
| Pipeline | Automatically schedule & multithread systems | FLECS_PIPELINE |
| Timer | Run systems at time intervals or at a rate | FLECS_TIMER |
| Meta | Flecs reflection system | FLECS_META |
| Units | Builtin unit types | FLECS_UNITS |
| JSON | JSON format | FLECS_JSON |
| Doc | Add documentation to components, systems & more | FLECS_DOC |
| Http | Tiny HTTP server for processing simple requests | FLECS_HTTP |
| Rest | REST API for showing entities in the browser | FLECS_REST |
| Parser | Parser utilities used by script & query DSL | FLECS_PARSER |
| Query DSL | Query DSL parser | FLECS_QUERY_DSL |
| Script | DSL for scenes, assets and configuration | FLECS_SCRIPT |
| Stats | Functions for collecting statistics | FLECS_STATS |
| Metrics | Create metrics from user-defined components | FLECS_METRICS |
| Alerts | Create alerts from user-defined queries | FLECS_ALERTS |
| Log | Extended tracing and error logging | FLECS_LOG |
| Journal | Journaling of API functions | FLECS_JOURNAL |
| App | Flecs application framework | FLECS_APP |
| OS API Impl | Default OS API implementation for Posix/Win32 | FLECS_OS_API_IMPL |
The following example shows how to build Flecs without any addons using bake. Run the command from the repository root:
To only build Flecs with the system addon, do:
The following example shows how to build Flecs without any addons using clang:
To only build Flecs with clang with the system addon, do: