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


i found number of similar questions (e.g. this, that or this), none of them helped me solve problem. have *.so file (from core of gnss-sdr) that, indicated by:

$nm libgnss_system_parameters_dyn.so  | c++filt  |grep gps_eph 

contains symbol gps_ephemeris::gps_ephemeris(), supposed constructor.

i've written minimal code:

#include <iostream> #include <core/system_parameters/gps_ephemeris.h>  int main(int argc,const char* argv[]) {     gps_ephemeris ge;     return 0;  } 

which compile with:

g++  main.cpp -std=c++0x -i some_include_path -l some_lib_path -l gnss_system_parameters_dyn` 

the linker complains:

/tmp/cchcvldg.o: in function `main': main.cpp:(.text+0x33): undefined reference `gps_ephemeris::gps_ephemeris()' collect2: error: ld returned 1 exit status 

i tried cmake, line generated similar (it added -rdynamic before linking), , still generated exact same linker error.

note both library , minimal code being compiled same compiler (g++-5), exact same flags , same c++0x standard.


addressing answer maxim egorushkin, line:

nm --demangle --defined-only --extern-only libgnss_system_parameters.so  |grep gps_eph 

doesn't output anything. however, symbol defined in static library (i.e. *.a library):

00000000000006b0 t gps_ephemeris::gps_ephemeris() 00000000000006b0 t gps_ephemeris::gps_ephemeris() 

knowing both generated cmake, in following way:

add_library(lib_name shared ${sources_etc}) #for *.so add_library(lib_name_2 ${sources_etc}) #for *.a 

there should no difference in symbols contained/defined in libraries, right? didn't notice in cmake's documentation on add_library. missing obvious?

the pedantically correct way check .so exports symbol nm --demangle --dynamic --defined-only --extern-only <lib.so> | grep <symbol>.

without --defined-only command shows undefined symbols.

without --extern-only shows symbols internal linkage unavailable linking.

it looks need link library because gps_ephemeris::gps_ephermeris() not resolved linking libgnss_system_parameters_dyn.so. way start library's documentation , examples.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -