Solved Undefined reference to symbol in static lib
-
There are
lib1.a
lib1 has class Lib1Class
lib2.a
lib2.a depends on lib1.a and use Lib1Class
app
app depends of lib2.a and app does not user lib1Class
TARGET = app LIBS += -Llibs_path -llib1 -llib2 INCLUDEPATH += headers_path
So when I build
app
I getundefined reference Lib1Class
when linking stage.Miracle occurs if I start using
Lib1Class
inapp
. i.e. in main.cpp create instance of classLib1Class
. Everything is linked and works.I tried to use
PRE_TARGETDEPS = $${libs_build_dir}/lib1.a
and it does not help.Help me to build
app
please. -
You need to reverse your link order when I'm correct
LIBS += -Llibs_path -llib2 -llib1
See also google for 'c++ link order static', e.g. https://eli.thegreenplace.net/2013/07/09/library-order-in-static-linking
-