简体   繁体   中英

Dynamic loading of .so file and reference to symbols

I am developing a Linux C++ application which uses application driver. Hardware developer provides SDK (includes and libraries). I want to use libraries dynamically via dlopen() in order to make app work without driver (or, maybe, with another driver furthermore).

When I used a method from one of libraries this way:

int (*VCI_OpenCAN)(PVCI_CAN_PARAM) = (int(*)(PVCI_CAN_PARAM))dlsym(_driver_library, "VCI_OpenCAN");

        int open_code = VCI_OpenCAN(&vcparam);

        if ( 0 == open_code) {
            qDebug() << "ERROR: " << open_code;
            exit(1);
        }

It told me that there is unresolved symbol Open_Com. Ok, it's probably called inside VCI_OpenCAN, but nm tells that there is U (undefined) symbol Open_Com in library (lib1.so, for instance). I digged around and found Open_Com in another library (lib2.so) bundled in SDK.

So the question is - how can I (and is it possible?) to enable dynamic loading of both libraries and to make them see symbols from each other or the only solution is static linking? Static linking works, the bundled example uses

$(CC) $(CFLAGS) $(LDFLAGS) -o $@ i7565H1H2.o ../lib/libI7565H1H2_64.so.1.0 ../lib/libi7k_64.so.1.0 $(AM_LDFLAGS)```

Manually dlopen the second library too, with the RTLD_GLOBAL flag is the solution.

_i7k_library = dlopen("/home/kkursor/tmp/libi7k_64.so.1.0", RTLD_GLOBAL | RTLD_NOW);
_driver_library = dlopen(config.value(section + "/driver_library").toString().toLocal8Bit(), RTLD_LAZY);

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM