The engine as one shared library #11

Closed
UnflavoredMeson/Primal_Plus_Plus
opened 2026-11-24 20:15:50 +00:00 by UnflavoredMeson · 0 comments
Owner

Why

Game code, the editor and the tests must share one world, one reflection registry and one log in a process. The fork found that out at the actor work and converted late. Doing it now means every later export is marked as it is written.

Decided

  • PrimalEngine.dll / libPrimalEngine.so; programs find it through RUNPATH $ORIGIN on Linux and by sitting next to it on Windows.
  • A game executable also links EngineMain, a static library with its main()/WinMain.
  • Exports are marked PRIMAL_API (in CommonDefinitions.h), in front, member by member, never on a class (that triggers MSVC C4251). Not on inline, constexpr or template functions.
  • Linux builds with hidden visibility, so a missing mark fails the Linux link like it would on Windows.
  • A class that game code derives from has no out-of-line virtual function (its vtable would be hidden on Linux).
  • One export macro while the engine is one library.

Read first

Steps

  • 1. Add PRIMAL_API and switch CMake and MSBuild to a shared PrimalEngine.
  • 2. Build EngineTest and UnitTests; mark each function the link reports missing. Read each one: is it really API?
  • 3. Split EngineMain out of Core/MainWin32.cpp (and a Linux main()).
  • 4. Add a unit test that loads a tiny test library with dlopen/LoadLibrary and sees the engine's state (proves one copy).

Done when

  • EngineTest and UnitTests link PrimalEngine on both OSes with 0 warnings (C4251 stays on).
  • The shared-state test passes on both OSes.

Claude can help with

  • Explaining a link error on one OS that the other doesn't show.
  • Reviewing which symbols became API.

Learn

  • What -fvisibility=hidden does, and why it makes Linux behave like Windows DLLs.
## Why Game code, the editor and the tests must share one world, one reflection registry and one log in a process. The fork found that out at the actor work and converted late. Doing it now means every later export is marked as it is written. ## Decided - `PrimalEngine.dll` / `libPrimalEngine.so`; programs find it through `RUNPATH $ORIGIN` on Linux and by sitting next to it on Windows. - A game executable also links `EngineMain`, a static library with its `main()`/`WinMain`. - Exports are marked `PRIMAL_API` (in `CommonDefinitions.h`), in front, member by member, never on a class (that triggers MSVC C4251). Not on inline, `constexpr` or template functions. - Linux builds with hidden visibility, so a missing mark fails the Linux link like it would on Windows. - A class that game code derives from has no out-of-line virtual function (its vtable would be hidden on Linux). - One export macro while the engine is one library. ## Read first - [Actors](https://forgejo.unflavoredmeson.com/UnflavoredMeson/Primal_Plus_Plus/wiki/Actors), section 17. - [Preferences](https://forgejo.unflavoredmeson.com/UnflavoredMeson/Primal_Plus_Plus/wiki/Preferences), "The engine library". ## Steps - [x] 1. Add `PRIMAL_API` and switch CMake and MSBuild to a shared `PrimalEngine`. - [x] 2. Build EngineTest and UnitTests; mark each function the link reports missing. Read each one: is it really API? - [x] 3. Split `EngineMain` out of `Core/MainWin32.cpp` (and a Linux `main()`). - [x] 4. Add a unit test that loads a tiny test library with `dlopen`/`LoadLibrary` and sees the engine's state (proves one copy). ## Done when - [x] EngineTest and UnitTests link `PrimalEngine` on both OSes with 0 warnings (C4251 stays on). - [x] The shared-state test passes on both OSes. ## Claude can help with - Explaining a link error on one OS that the other doesn't show. - Reviewing which symbols became API. ## Learn - What `-fvisibility=hidden` does, and why it makes Linux behave like Windows DLLs.
Sign in to join this conversation.
No assignees
No project
Blocks
#16 Job system module primal.jobs
UnflavoredMeson/Primal_Plus_Plus
#21 Reflection generator PrimalReflectGen
UnflavoredMeson/Primal_Plus_Plus
Depends on
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
UnflavoredMeson/Primal_Plus_Plus#11
No description provided.