0

I have an app which linked to testA lib that in turn linked to testB lib. There is bellow link error when I build my app. I can't figure out why this happened.

More information, checkConnection(), reqGetReference() and test_register_app() all from testB lib, so why the error is just with the first two functions

test-pc$ make CXXFLAGS='-g -O0 -frtti -fexceptions'
../libtestA/.libs/libtestA.so: undefined reference to `test_namespace::checkConnection()'
../libtestA/.libs/libtestA.so: undefined reference to `test_namespace::reqGetReference(char const*)'
collect2: error: ld returned 1 exit status
make: *** [tf_app] Error 1

test-pc$ nm -D ../libtestA/.libs/libtestA.so | grep checkConnection
                 U _ZN15test_namespace15checkConnectionEv

test-pc$ nm -D ../libtestA/.libs/libtestA.so | grep reqGetReference
                 U _ZN15test_namespace15reqGetReferenceEPKc

test-pc$ nm -D ../libtestA/.libs/libtestA.so | grep test_register
                 U _ZN15test_namespace24test_register_appEPKcPFbPcS2_ES4_S4_S4_PFbS2_ES6_PFbS2_llEPFbS2_lllESA_S6_

test-pc$ nm -D ../libtestB/.libs/libtestB.so | grep checkConnection
0000000000016f5d T _ZN15test_namespace15checkConnectionEv

test-pc$ nm -D ../libtestB/.libs/libtestB.so | grep reqGetReference
0000000000016b9a T _ZN15test_namespace15reqGetReferenceEPKc

test-pc$ nm -D ../libtestB/.libs/libtestB.so | grep test_register
0000000000015c2a T _ZN15test_namespace24test_register_appEPKcPFbPcS2_ES4_S4_S4_PFbS2_ES6_PFbS2_llEPFbS2_lllESA_S6_

test-pc$ ldd ../libtestA/.libs/libtestA.so
    linux-vdso.so.1 =>  (0x00007ffd659d2000)
    libtestB.so.1 => libtestB/.libs/libtestB.so.1 (0x00007f994172b000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f994150d000)
    libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f9941209000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9940e44000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f9940c2e000)
    libpt.so.2.10.7 => /usr/local/lib/libpt.so.2.10.7 (0x00007f99406af000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f9942701000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f99403a9000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f99401a1000)
    libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f993fb67000)
    libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f993f93d000)
    libodbc.so.1 => /usr/lib/x86_64-linux-gnu/libodbc.so.1 (0x00007f993f6d6000)
    libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f993f4bb000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f993f2b7000)
    libltdl.so.7 => /usr/lib/x86_64-linux-gnu/libltdl.so.7 (0x00007f993f0ad000)

Can anyone help me? Thanks in advance!

Reply to the answers, I add here additional information

I use libtool and automake and here is my Makefile

# Makefile.ac for libtestA
lib_LTLIBRARIES = libtestA.la
libtestA_la_SOURCES = Src files

libtestA_la_CPPFLAGS= -I@top_srcdir@/src/test/include (here header files from libs)

libtestA_la_LDFLAGS = 

libtestA_la_LIBADD =   -lpthread \
                ../libtestB/libtestB.la

# Makefile.ac for my_app
bin_PROGRAMS = my_app
my_app_SOURCES = my_app.cpp
my_app_CPPFLAGS = -I@top_srcdir@/src/test/include
my_app_LDADD = ../libtestA/libtestA.la

EXTRA_DIST = 

# build app command
/bin/bash ../../../libtool --silent --tag=CXX --mode=link g++ -g -O0 -frtti -fexceptions -L/usr/local/lib -o my_app my_app-my_app.o -lexpat -ldl -lpthread -lcrypto ../libtestA/libtestA.la

Additional, It just works fine with Centos but not with my Ubuntu.

dvn0zzz
  • 337
  • 3
  • 13
  • I already checked from this http://stackoverflow.com/questions/10456581/undefined-reference-to-symbol-even-when-nm-indicates-that-this-symbol-is-present but that wouldn't help – dvn0zzz Jan 08 '16 at 04:51
  • You should show your actual link command. – Employed Russian Jan 08 '16 at 05:04
  • 1
    Linker errors are notoriously difficult to debug here, given that it depends on all your includes, as well as how your system resolves paths, and how your build system is set up to compile, hence the reason for that FAQ answer you linked. So in lieu of any useful details, I'll take a stab: you have a circular dependency. – AndyG Jan 08 '16 at 05:04

0 Answers0