Simple mod
#3748
-
Is there a way to add a simple "modding" system?? Here is my current setup, but it's not working... Main.cpp: #include <dlfcn.h>
#include <raylib.h>
typedef void (*UpdateFunction)();
UpdateFunction update;
int main() {
InitWindow(1000, 600, "Mod loading test");
void* handle = dlopen("mod.so", RTLD_NOW | RTLD_GLOBAL);
update = (UpdateFunction)dlsym(handle, "Update");
while(!WindowShouldClose()) {
BeginDrawing();
ClearBackground(WHITE);
update();
EndDrawing();
}
dlclose(handle);
CloseWindow();
} Mod.cpp: #include <raylib.h>
extern "C" {
void Update() {
ClearBackground(RED);
}
}; $ g++ mod.cpp -shared -fPIC -lraylib -o mod.so
$ g++ main.cpp -lraylib -ldl -g -o main But when I run Backtrace:
|
Beta Was this translation helpful? Give feedback.
Answered by
Peter0x44
Feb 1, 2024
Replies: 1 comment 1 reply
-
Is |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Zahon7
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is
-lraylib
a static, or shared library in this case? It must be a shared library for this to work, since raylib has global state, and if linked static, both the so and your executable will have their own copies of this state.