Using any C++ library in Godot
4 hours ago
- Godot is an open-source game engine where most games are written in GDScript, but GDScript cannot call native code directly.
- GDExtension allows loading C++ shared libraries at runtime, and godot-cpp provides C++ bindings to expose native code as regular engine classes.
- Building C++ extensions for multiple platforms is complex; Conan simplifies this by managing dependencies and providing precompiled godot-cpp and other libraries.
- The example creates a Swarm node using the flecs ECS library to simulate 100,000 particles, demonstrating performance benefits of C++.
- godot-cpp 10 works with any Godot 4.3+ by selecting an api_version option, and supports three targets (template_debug, template_release, editor) matching Godot builds.
- With Conan, the extension is built using CMake, linking godot-cpp and flecs, and outputs the library directly into the Godot project's bin folder.
- GDExtension classes are registered with GDREGISTER_RUNTIME_CLASS and appear as built-in nodes in the editor, but only run during gameplay.
- Conan handles cross-platform builds easily, and the post includes a note about statically linking libstdc++ on Linux for wider compatibility.