The problem is I use dlopen to load a library (the .so is written by me, it’s not a system library), but I got the error shown in the title.
- I have included
dlfcn.h - in compiler, I used the
-ldlcommand - What I want to load is just the source code folder, I tried to add
-L., but it did not work.
If the library you want to dlopen is not in the standard search path you have a number of options:
Specify the full path to the file in dlopen
dlopen("/full/path/to/libfile.so");Add the path to the library via LD_LIBRARY_PATH
LD_LIBRARY_PATH=/path/to/library/ ./executableuse the ld -rpath option to add a library path to the application.
g++ -link stuff- -Wl,-rpath=/path/to/library/Note that options 1 & 3 hardcode the library path into your application. -rpath does have an option to specify a relative path, i.e.
Will embed a relative path into the application.