c++ - Static linking failed although the name exists -


i'm trying link static library, libcovis.a. looks fine still have

undefined reference `covig_publicdemo::moins::reset()'

i checked name exists in library

$nm libcovis.a | grep reset

...

_zn16covig_publicdemo5moins5resetev

...

i'm using linking arguments -l/path/to/libcovis.a -lcovis

what doing wrong ?

edit: error might else, if

gcc main.cpp -i/usr/include/opencv -i/usr/include/cairo -i../../source -o slam -rdynamic -lglu -lgl -lsm -lice -lx11 -lxext -lglut -lxi -lxml2 -lboost_filesystem-mt -llapack -lblas -lcv -lcxcore -lcvaux -lhighgui -lcairo ../../source/libcovis.a ../../source/contrib/gnuplot_i/libcovis_contrib_gnuplot_i.a -lgl2ps

it works !

but when i'm in kdevelop using cmake, doesn't work anymore. use

cmake_exe_linker_flags:string=-rdynamic -lglu -lgl -lsm -lice -lx11 -lxext -lglut -lxi -lxml2 -lboost_filesystem-mt -llapack -lblas -lcv -lcxcore -lcvaux -lhighgui -lcairo /usr/local/src/covis-0.0.0-1/source/libcovis.a /usr/local/src/covis-0.0.0-1/source/contrib/gnuplot_i/libcovis_contrib_gnuplot_i.a -lgl2ps

cmake_cxx_flags:string=-i/usr/local/src/covis-0.0.0-1/source -i/usr/include/opencv -i/usr/include/cairo

the difference can see paths absolute , not relative, if couldn't find libs, it...

there 2 different issues there, first of simplest, have used wrong compiler options. -l option tells linker in directory when looking library. -l tells link specific library. link use:

g++ -o test test.o -l/path/to -lcovis

or

g++ -o test test.o -l/path/to/libcovis.a

to force static linking if same library present dynamic library in same directory.

the second potential issue order of static libraries in linker command line matter, might issue if there dependency on different static libs.

g++ -o test tests.o -ldependent -lprovider

the linker process libraries in order in command line, , each static lib pull symbols required (with information linker has @ time). in command line above, linker extract dependent symbols needs test.o, , might in turn add new undefined symbols program (the dependencies of dependent). when processes provider fill in symbols. if order reversed in command line, symbols required dependent not test.o not added executable, linker not know symbols needed when processing provider.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -