Hey guys, I've been experimenting a bit with hotloading shared libs on linux lately.
However, once I started to have many functions to manually link I decided to try and link the lib at once at compile time the same way we do with sdl for example.
For what I've looked around, it seems there are couple options. Copying the lib into /usr/lib and name it something like libmy_lib.so
, then link it with -lmy_lib and that works. But I would like to have my lib inside my project's folder, also having the lib at /usr/lib means I need to compile with sudo which is a pain.
I've struggled a bit to compile it having the lib locally, it just wouldn't find it. After some more research I found out about "soname". I don't quite understand it but I got it to work with something like that:
echo "Compiling renderer..."
g++ opengl_renderer.cpp -fPIC -Wl,-soname,libgl_render.so
-ggdb -shared -o lib/libgl_render.so
echo "Compiling engine..."
g++ main.cpp $warn -ldl -ggdb -lGL -lSDL2 -L ~/ProjectFolder/lib -lgl_render
The thing is though, to run this it seems I need to set LD_LIBRARY_PATH which is unfortunate...
So my question is, for any folks which messed with this in the past, is there a better option I'm missing out? Or maybe is it best to actually put the lib at /usr/lib? Anyhow, thanks in advance!