Search code examples
javajava-native-interface

Linux Java: load .so dynamically without dlopen


I have 2 libs (first.so and second.so), and I need to call a function from 'second.so' in the 'first.so'. Now in my case I don't want to do static link to second.so. I need to call it dynamically. So what I need is to use

System.loadlibrary("first.so") System.loadlibrary("second.so")

Now in the c++ code of "first.so" I need to call a function from the second.so. Can I do this without dlopen?


Solution

  • When you compile the C++ code and build your first.so you instruct the linker to use external symbols from the second library. The second library must be on the library search path at run time so that the systems dynamic linker can find it.