i am cross compiling a program for a embedded system. The program uses a shared library, which i openend like this.
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h> //needed for dynamic linking
void *FunctionLib; //Handle to shared lib file
int (*Function)(); //Pointer to loaded routine
const char *dlError; //Pointer to error string
int main( argc, argv )
{
int rc; //return codes
printf("start...\n");
//Open Dynamic Loadable Libary with absolute path
FunctionLib = dlopen("/lalabu/sharedLib.so",RTLD_LAZY | RTLD_GLOBAL);
dlError = dlerror();
printf("Open sharedLib.so returns: %s \n", dlError);
if( dlError ) exit(1);
//Find function
Function = dlsym( FunctionLib, "getSomething");
dlError = dlerror();
printf("Find symbol getSomething returns: %s \n", dlError);
if( dlError ) exit(1);
...
I am compiling the code with the following command
mips-linux-uclibc-gcc -Wall -ldl ./dynamic_linking.c -o /dynamic_linking
which works without any warnings and stuff.
If i now try to execute this code on my device, i get the following error:
# ./dynamic_linking
start...
Open sharedLib.so returns: (null)
Find symbol getSomething returns: Unable to resolve symbol
./dynamic_linking: can't resolv '_ZNSt8ios_base4InitD1Ev'
If i take a look with IDA which functions sharedLib.so wants to import, i see the Function (or symbol?) '_ZNSt8ios_base4InitD1Ev' and where it should be (libc.so.0).
If i take a look at libc.so.0, again with IDA, i don't see a function called like this. Also nothing like ios_base, ios or base.
I tried already various flag combinations with dlopen() which resulted always in the above error, except when i use RTLD_NOW instead of RTLD_LAZY i get
Segmentation fault (core dumped)
instead of
./dynamic_linking: can't resolv '_ZNSt8ios_base4InitD1Ev'
Furthermore i tried a few gcc linking-options like rdynamic, always with the same result.
Moreover i tried to use a shared library which doesn't use _ZNSt8ios_base4InitD1Ev, the 'libc.so.0' to check if my c-code is working. I only changed the name and the absolute path and deleted the find function part. It worked without errors.
As you may recognize from my post, i just started cross compiling and using dynamic libraries, so maybe my fault is somewhere else. Besides, I am not sure if i even understand where the problem is, so any hints are welcome. If you need further information, i'd be happy to give them to you.
Greetings, Pingu