Make globals available accross DLL boundaries #5

Open
opened 2024-02-09 08:32:01 +01:00 by kevin · 0 comments
Owner

The current pattern does not work across dll boundaries, but simply doing a extern DL_IMPORT foo g_foo; in the header results in a warning:

3>LINK : warning LNK4217: symbol 'g_main_loop' defined in 'main_loop.c.obj' is imported by 'app.c.obj' in function 'rtWin32Entry'

One idea is to instead offer functions for this:

RT_DLLEXPORT rt_main_loop *rtGetMainLoop(void);

Pro: Should obviously work
Con: "Unnecessary" function calls.

This problem could be mitigated if the "client" DLL simply caches the result in a global variable. If, for example, the game uses the main loop constantly, it could do:

rt_main_loop *g_main_loop;

void GameInit(void) {
   g_main_loop = rtGetMainLoop();

and all code after that just uses the g_main_loop variable.

Question: Would this work with linux builds, where we don't need DLLEXPORT/IMPORT to access other codes variables?

The current pattern does not work across dll boundaries, but simply doing a `extern DL_IMPORT foo g_foo;` in the header results in a warning: > 3>LINK : warning LNK4217: symbol 'g_main_loop' defined in 'main_loop.c.obj' is imported by 'app.c.obj' in function 'rtWin32Entry' One idea is to instead offer functions for this: ```C RT_DLLEXPORT rt_main_loop *rtGetMainLoop(void); ``` Pro: Should obviously work Con: "Unnecessary" function calls. This problem could be mitigated if the "client" DLL simply caches the result in a global variable. If, for example, the game uses the main loop constantly, it could do: ```C rt_main_loop *g_main_loop; void GameInit(void) { g_main_loop = rtGetMainLoop(); ``` and all code after that just uses the g_main_loop variable. **Question**: Would this work with linux builds, where we don't need DLLEXPORT/IMPORT to access other codes variables?
kevin added the
priority
medium
kind
refactoring
labels 2024-06-18 12:20:14 +02:00
kevin added this to the Version 0.1 milestone 2024-06-18 12:21:58 +02:00
Sign in to join this conversation.
No description provided.