I am trying to build a shared library that depends on another shared library on which I have no control. Here is how I build it:
g++ -fPIC -Wall -Wextra -O2 -g -fpermissive -Wl,--no-allow-shlib-undefined -Wl,--no-undefined \
-I$JAVA_HOME/include -I$JAVA_HOME/include/linux -I/opt/softkinetic/DepthSenseSDK/include \
-L/opt/softkinetic/DepthSenseSDK/lib \
-lDepthSense -lDepthSensePlugins -lturbojpeg -c -o NativeDs325.o \
NativeDs325.cpp
g++ -shared -o libds325.so NativeDs325.o
The build step goes fine, but when I load my library, it throws an undefined symbol error
. When I look into the libraries, here is what I found
$ldd -d libds325.so
linux-vdso.so.1 => (0x00007fff94bfe000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f727167d000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f7271467000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f72710a6000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f7270daa000)
/lib64/ld-linux-x86-64.so.2 (0x00007f7271ba5000)
undefined symbol: _ZTIN10DepthSense9ExceptionE (./libds325.so)
undefined symbol: _ZTIN10DepthSense16EventHandlerBaseE (./libds325.so)
undefined symbol: _ZN10DepthSense7ContextD1Ev (./libds325.so)
undefined symbol: _ZN10DepthSense9DepthNodeD1Ev (./libds325.so)
And when I look into the library I depend on and on which I have no control:
$nm -D libds325.so | grep _ZTIN10DepthSense9ExceptionE
U _ZTIN10DepthSense9ExceptionE
$nm -D libds325.so | grep _ZTIN10DepthSense16EventHandlerBaseE
U _ZTIN10DepthSense16EventHandlerBaseE
So those symbols are not defined in the libraries I have. Is there anything I can do to solve my problem or am I totally dependent on the supplier of the library? Is there something I'm missing entirely?
Thanks in advance
I had two problems in the way I was building the library:
1) As per this question undefined reference to symbol even when nm indicates that this symbol is present in the shared library, libraries must be listed after the objects that use them so:
g++ NativeDs325.cpp -fPIC -Wall -Wextra -O2 -g -fpermissive -Wl,--no-allow-shlib-undefined -Wl,--no-undefined \
-I$JAVA_HOME/include -I$JAVA_HOME/include/linux -I/opt/softkinetic/DepthSenseSDK/include \
-L/opt/softkinetic/DepthSenseSDK/lib \
-lDepthSense -lDepthSensePlugins -lturbojpeg -c -o NativeDs325.o \
2) When linking, I needed to add the libraries to include in the final shared library:
g++ -shared -o libds325.so NativeDs325.o -L/opt/softkinetic/DepthSenseSDK/lib \
-lDepthSense -lDepthSensePlugins -lturbojpeg