I need a help about dynamically loading a library on C++ code.
I have several libraries having same APIs ( ex: libtest_10.so and libtest_20.so).
Also I know that I have to link a shared library on build time even when I load the library with dlopen() on run-time.
But in my case, I linked the libtest_1.so and libtest_2.so to an test executable on CMakeLists.txt.
PROJECT(test_main)
ADD_EXECUTABLE(${PROJECT_NAME} main.cpp)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wall -Wextra -rdynamic")
FIND_LIBRARY(LIB_TEST1 NAME test_1 HINTS ../prebuilts)
MESSAGE("libtest_1.so :" ${LIB_TEST1})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PUBLIC ${LIB_TEST1})
FIND_LIBRARY(LIB_TEST2 NAME test_2 HINTS ../prebuilts)
MESSAGE("libtest_2.so :" ${LIB_TEST2})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PUBLIC ${LIB_TEST2})
and load the library libtest_2.so with dlopen as below.
#include <dlfcn.h>
void* test_lib_handle = dlopen("/usr/lib/libtest_2.so", RTLD_NOW);
(...)
But when I run the executable, I could see the log from not 'libtest_2.so' but 'libtest_1.so'.
How can I load the library I want to pick ? anyone help me about the compile options or any other proper method?