I've struggled with dlopen
and undefined symbols.
What I have and tried so far:
libraryA.a with function functionA()
libraryA.so with function functionA()
libraryB.so which is using functionA()
an executable which loads libraryB.so with dlopen.
What I got is:
undefined symbol: functionA
How I build:
libraryA:
gcc -std=gnu11 -O2 -g -Wall -Wstack-usage=2000 -Werror
-fdiagnostics-color -fPIC -pipe -fsigned-char -fno-asynchronous-unwind-tables
-fno-stack-protector -I../include/ libraryA.c -shared -o libraryA.so
libraryB:
gcc -std=gnu11 -O2 -g -Wall -Wstack-usage=2000 -Werror -fdiagnostics-color
-fPIC -pipe -fsigned-char -fno-asynchronous-unwind-tables
-fno-stack-protector -I../include/ libraryB.c -shared -o libraryB.so
Build executable:
-std=gnu99 -pipe -fno-strict-aliasing -fsigned-char -fno-asynchronous-unwind-tables
-fno-stack-protector -Wall -Wextra -Wundef -Wno-sign-compare -Wno-unused-parameter
-Wno-packed-bitfield-compat -Wno-misleading-indentation -fomit-frame-pointer
-maccumulate-outgoing-args -fPIC -m64 -g3 -gdwarf-2 -fno-common -Wstrict-prototypes
-Wimplicit -Wno-pointer-sign -c executable.c -o executable libraryA.a
Open libraryB in executable like this here:
void *handle = dlopen("libraryB.so", RTLD_LAZY);
if (handle == NULL) {
fprintf( stderr, "Load error (%s)!\n", dlerror());
return NULL;
}
How can I fix this behavior? I also tried the flag -rdynamic without success. I also tried different dlopen flags but also without success.
Can anyone please help me?