Accessing .so libraries using dlopen() throws undefined symbol error

后端 未结 4 1695
生来不讨喜
生来不讨喜 2021-02-04 09:55

I\'m trying to dynamically load a camera library .so file into a Linux executable to gain access to simple camera functions.

I\'m attempting to do this by:



        
4条回答
  •  粉色の甜心
    2021-02-04 10:30

    Most likely, libCamera.so uses a symbol defined in a shared library without depending on that library.

    1. Find a culprit. Take a real executable which links against libCamera.so (and it works). List its dependencies with ldd /path/to/executable. Among them should be a library which has a definition for ZTVN10_cxxabiv117__class_type_infoE (use grep to select likely candidates, nm -D on a library to be sure). That library won't be in the list shown by ldd ./libCamera.so.

    2. Solve a problem. Load the library found in step 1 by dlopen first (use RTLD_GLOBAL there as well).

    3. If there is a problem with another symbol, goto step 1.

    4. If newly-added libraries have the same problem too, goto step 1.

    5. Tell library authors to please fix their linking.

    It could also happen that one of the prerequisites in ldd ./libCamera.so got upgraded and lost a symbol definition (maybe it was recompiled with a compiler which does name mangling differently). Then you won't find the culprit in step 1, and there is no solution but downgrading something again.

提交回复
热议问题