I need to link a program statically with soci for security reasons.
I built the static libraries libsoci_core.a and libsoci_postgresql.a as my backend is postgresql.
My issue is that when I build my program with these libraries I get link errors.
[...]/lib/libsoci_core.a(backend-loader.cpp.o): In function `(anonymous namespace)::do_unload(std::basic_string, std::allocator > const&)':
backend-loader.cpp:(.text+0x623): undefined reference to `dlclose'
Looking at the code in backend-loader.cpp, it calls dlclose and other dynamic library loading functions.
So I am wondering if it is even possible to avoid these errors and have a 'true' static build.
Or what option should I use to not have this error and would the code call the static posgresql library?
thank you!
Since you are trying to build a statically linked library, the dl* functions need to be removed/stubbed out.
One way would be to create a dlstub.c file with your own functions and link them to the library.
Using prototypes from (/usr/include/dlfcn.h):
#include <dlfcn.h>
int dlclose(void *){}
char *dlerror(void){}
void *dlopen(const char *, int){}
void *dlsym(void *restrict, const char *restrict){}
Compile your stub functions into a *.o file, and link it to your compile command:
gcc -c -O2 -g dlstubs.c
gcc -static ... -o dlstubs.o ...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.