Message from discussion
Dynamic linking with undefined symbol giving runtime error
Received: by 10.224.189.75 with SMTP id dd11mr2183043qab.6.1348170112520;
Thu, 20 Sep 2012 12:41:52 -0700 (PDT)
Received: by 10.52.70.82 with SMTP id k18mr582214vdu.1.1348170112370; Thu, 20
Sep 2012 12:41:52 -0700 (PDT)
Path: t12ni1094712qak.0!nntp.google.com!l8no153890qao.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups: gnu.gcc.help
Date: Thu, 20 Sep 2012 12:41:52 -0700 (PDT)
Complaints-To: groups-abuse@google.com
Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=115.186.117.203;
posting-account=quvlYQoAAACLnTwCKmbRhpmwwBdba1sY
NNTP-Posting-Host: 115.186.117.203
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7c1dffda-6c06-43f9-9c9d-ce827a320962@googlegroups.com>
Subject: Dynamic linking with undefined symbol giving runtime error
From: aun...@gmail.com
Injection-Date: Thu, 20 Sep 2012 19:41:52 +0000
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
I am trying to use a lib(mongodb C driver) in my application but stuck badl=
y in a linking problem. The libs are 4 objects (libbson.a + libbson.so + li=
bmongoc.a + libmongoc.so). My Makefile has libraries added like this. The r=
elevant ones are -lmongoc and -lbson
srv_la_LIBADD =3D -lrt -lcre2 -lre2 -lcurl -lpthread -lmongoc \
-lbson @MODULES_LIBADD@
The driver libs are compiled and installed successfully at /usr/local/lib. =
I have even made links to these in /lib and /lib64 directories
The problem is that my application gets compiled and linked successfully b=
ut the final srv.so contains UNDEFINED symbols from the mongo C driver(libm=
ongoc.a) which give runtime errors.
Error loading module srv.so:/usr/local/c_icap/lib/c_icap/srv.so: unde=
fined symbol: mongo_cursor_set_query
The linker line from Make process is:
libtool: link: gcc -shared -fPIC -DPIC .libs/srv_la-srv.o
.libs/srv_la-erd.o=20
.libs/srv_la-erd_list.o=20
.libs/srv_la-str_util.o=20
.libs/srv_la-url_util.o=20
.libs/srv_la-easyzlib.o=20
.libs/srv_la-state_db.o=20
.libs/srv_la-data_access_api.o=20
.libs/srv_la-cJSON.o =20
.libs/srv_la-clib_es.o =20
-lrt -lcre2 -lre2 /usr/lib/x86_64-linux-gnu/libcurl.so=20
-lpthread -lmongoc -lbson -O2 -O2 -Wl,-soname -Wl
,srv.so -o .libs/srv.so
Specifically the objdump of the srv.so says:
root@talha:/webproxy# objdump -t services/.libs/srv.so|grep "mongo"
0000000000000000 *UND* 0000000000000000 mongo_cursor_=
set_query
0000000000000000 *UND* 0000000000000000 mongo_destroy
0000000000000000 *UND* 0000000000000000 mongo_cmd_aut=
henticate
0000000000000000 *UND* 0000000000000000 mongo_create_=
index
0000000000000000 *UND* 0000000000000000 mongo_cursor_=
destroy
0000000000000000 *UND* 0000000000000000 mongo_update
0000000000000000 *UND* 0000000000000000 mongo_cursor_=
next
0000000000000000 *UND* 0000000000000000 mongo_cursor_=
init
0000000000000000 *UND* 0000000000000000 mongo_remove
0000000000000000 *UND* 0000000000000000 mongo_connect
0000000000000000 *UND* 0000000000000000 mongo_cursor_=
bson
Whereas the bson symbols are added correctly. This is strange as both the l=
ibs are installed at the same location and have been added in the Makefile.
I tried to link libmongoc.a(static) statically but that results in the link=
er giving a portability warning of srv.so linking against libmongoc.a and p=
roduces final srv.a instead of src.so(but this kind of makes sense). Even t=
hen, the symbols are not present in srv.a. Which is even more strange to me=
.
The the libs were built with -fPIC flag so that part is catered. Any helpfu=
l hints? Why is it not linking properly and why is the linker not giving an=
y errors?