Undefined Reference to Symbol Even When Nm Indicates That This Symbol Is Present in the Shared Library

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 (more precisely, a library will be used only if it contains a symbol that satisfies an undefined reference known at the time it is encountered). Move the -lmnl to the end of the command.

undefined reference to symbol even when nm indicates that this symbol is present in the shared library 2

_ZN5nglib7Ng_InitEv demangles to nglib::Ng_Init() which is not the same as Ng_Init().

g++ undefined reference although symbol is present in *.so file

The pedantically correct way to check that a .so exports a symbol is nm --demangle --dynamic --defined-only --extern-only <lib.so> | grep <symbol>.

Without --defined-only your command also shows undefined symbols.

Without --extern-only it also shows symbols with internal linkage which are unavailable for linking.

It looks like you need to link another library because Gps_Ephemeris::Gps_Ephermeris() is not resolved by linking libgnss_system_parameters_dyn.so. A good way to start is that library's documentation and examples.

Depending on a shared library that has an undefined symbol

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

Getting undefined reference error but nm shows symbol present

It looks like you have an ABI mismatch issue. ABI is "Application Binary Interface", basically the specification for exactly how arguments make it onto the stack (or are put in registers) and various other things like that.

Try making sure your code is compiled with the -std=c++11 (or -std=gnu++11 if you use any GNU extensions) flag. It looks like that's how libkml was compiled. C++11 has a bunch of new features that require an ABI compatibility break with pre-C++11. C++14 and C++1z are less drastic changes, but they may also break ABI compatibility, I'm not sure. In this case though, the demangled symbol is clear, libkml wants at least C++11.

g++ Undefined Symbol Error using shared library

You need to set your LD_LIBRARY_PATH environment variable to include the path to your development version of the library. This will ensure the run time linker (ld.so) will find it when you run your application.

Your build settings are fine but they don't affect what happens at run time. There are ways to "bake" paths into the executable at build time if you really want to. See the man page for ld.so to see how it searches for libraries.



Related Topics



Leave a reply



Submit