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
Differencebetween "Var=${Var:-Word}" and "Var=${Var:=Word}"
How to Return Exit Code 0 from a Failed Command
What Does "|" Mean in a Terminal Command Line
Linux Combine Two Files by Column
Print on Terminal and into File Simultaneously
Linux Run Kernel Probe Systemtap Script Failed with Semantic Error: No Match"
Git Pull Permission Denied Linux
In Linux, How to Test Whether the Output of a Program Is Going to a Live Terminal or to a File
How to Download PHP Script from a Web Page with Wget
Unix 'Alias' Fails with 'Awk' Command
Capture Both Exit Status and Output from a System Call in R
What's the Practical Limit on the Size of Single Packet Transmitted Over Domain Socket
Is /Dev/Random Considered Truly Random
Ps: Clean Way to Only Get Parent Processes
Openssl Encoding Errors While Converting Cer to Pem
Error: Clgetplatformids -1001 When Running Opencl Code (Linux)