Probleme compilling shared library (.so)

Compilation and installation of DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
valabregue
Posts: 3
Joined: Mon, 2010-10-25, 16:00

Probleme compilling shared library (.so)

#1 Post by valabregue »

Dear all

I try to complie dcmtk in a linux 64 server (centos 4.5) with gcc 4.1.2 to obtain dynamic shared library (.so) in order link them in an other application.

I follow the FAQ #13 but I am not so sure.
for CFLAGS and CXXFLAGS I just changed the -O option with
-O2 -fPIC (and I let all other option )
should I removed them or keep -O ?

So the config/Makefile.def has the following setting


CC = gcc
CFLAGS = -O2 -fPIC -I/usr/include/libxml2 -D_REENTRANT -D_XOPEN_SOURCE_EXTENDED -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -D_BSD_COMPAT -D_OSF_SOURCE -D_POSIX_C_SOURCE=199506L -Wall
CXX = c++
CXXFLAGS = -O2 -fPIC -I/usr/include/libxml2 -D_REENTRANT -D_XOPEN_SOURCE_EXTENDED -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -D_BSD_COMPAT -D_OSF_SOURCE -D_POSIX_C_SOURCE=199506L -Wall
CPPFLAGS =
LDFLAGS =
RANLIB = :
AR = gcc
ARFLAGS = -shared -o
LIBS = -lrt -lpthread -lnsl
MATHLIBS = -lm
OPENSSLLIBS = -lssl -lcrypto -ldl
TIFFLIBS = -ltiff -ljpeg -lz
PNGLIBS = -lpng
ZLIBLIBS = -lz
XMLLIBS = -lxml2
TCPWRAPPERLIBS = -lwrap
LIBEXT = so
BINEXT =


While the binary seems to work find I have a lot of undefined reference when I try
ld libdcmtls.so

for instance

ld dcmtk_bin_64/lib/libdcmtls.so
ld: warning: cannot find entry symbol _start; not setting start address
dcmtk_bin_64/lib/libdcmtls.so: undefined reference to `TLSv1_method'
dcmtk_bin_64/lib/libdcmtls.so: undefined reference to `OFString::~OFString()'
dcmtk_bin_64/lib/libdcmtls.so: undefined reference to `SSL_connect'
dcmtk_bin_64/lib/libdcmtls.so: undefined reference to `i2d_X509'
...


ld dcmtk_bin_64/lib/libdcmdata.so
ld: warning: cannot find entry symbol _start; not setting start address
dcmtk_bin_64/lib/libdcmdata.so: undefined reference to `vtable for OFConditionConst'
dcmtk_bin_64/lib/libdcmdata.so: undefined reference to `OFString::~OFString()'
dcmtk_bin_64/lib/libdcmdata.so: undefined reference to `OFTime::getISOFormattedTime(OFString&, bool, bool, bool, bool) const'
dcmtk_bin_64/lib/libdcmdata.so: undefined reference to `std::basic_ostringstream<char, std::char_traits<char>, std::allocator<char> >::~basic_ostringstream()'

...


Many thanks for your help

Romain

[quote][/quote]

Uli Schlachter
DCMTK Developer
Posts: 120
Joined: Thu, 2009-11-26, 08:15

#2 Post by Uli Schlachter »

Hi,

static libraries can't specify dependencies on other libs, so when building libraries, the Makefiles don't specify the dependencies on these libs. When building shared objects, the same is done, but now there are unresolved symbols in these shared objects.

The way you are supposed to handle this is to also specify the libraries that the DCMTK libraries you use depend on. In your example with dcmdata, this is ofstd (and oflog if you are using a recent version). dcmtls additonally needs libssl and libcrypt.

Cheers,
Uli

valabregue
Posts: 3
Joined: Mon, 2010-10-25, 16:00

#3 Post by valabregue »

Hello

Thank you for your reply and sorry for having so basic knowledge on compilation...
Could you precise how do I specify the other library?
is it in the dcmtk makfile ? or just in the LD_LYBRARYPATH ?

and How do you know which library should I add.
for instance the

Code: Select all

ld lib/libdcmnet.so 
ld: warning: cannot find entry symbol _start; not setting start address
lib/libdcmnet.so: undefined reference to `DcmShortString::DcmShortString(DcmTag const&, unsigned int)'
lib/libdcmnet.so: undefined reference to `vtable for OFConditionConst'
lib/libdcmnet.so: undefined reference to `OFString::~OFString()'
lib/libdcmnet.so: undefined reference to `typeinfo for OFListBase'
lib/libdcmnet.so: undefined reference to `DcmTag::DcmTag(DcmTagKey const&)'
lib/libdcmnet.so: undefined reference to `std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::str() const'
lib/libdcmnet.so: undefined reference to `DcmStack::top() const'
lib/libdcmnet.so: undefined reference to `OFConfigFile::OFConfigFile(_IO_FILE*)'
...
thank you for your help

Romain

valabregue
Posts: 3
Joined: Mon, 2010-10-25, 16:00

#4 Post by valabregue »

Hello


I try by myself to change the creation of the .so
by default I makefile generate the command

Code: Select all

gcc  -shared -o libdcmnet.so assoc.o cond.o dcompat.o dimcancl.o dimcmd.o dimdump.o dimecho.o dimfind.o dimmove.o dimse.o dimstore.o diutil.o dulconst.o dulextra.o dulfsm.o dulparse.o dulpres.o dul.o lst.o extneg.o dimget.o dcmlayer.o dcmtrans.o dcasccfg.o dcasccff.o dccfuidh.o dccftsmp.o dccfpcmp.o dccfrsmp.o dccfenmp.o dccfprmp.o 
So there where no linking to any library ?
I tried to explicitely add some linking

Code: Select all

gcc -L/usr/cenir/src/PTK/dcmtk-3.5.4/ofstd/libsrc/ -L/usr/cenir/src/PTK/dcmtk-3.5.4/dcmdata/libsrc -shared -o libdcmnet.so assoc.o cond.o dcompat.o dimcancl.o dimcmd.o dimdump.o dimecho.o dimfind.o dimmove.o dimse.o dimstore.o diutil.o dulconst.o dulextra.o dulfsm.o dulparse.o dulpres.o dul.o lst.o extneg.o dimget.o dcmlayer.o dcmtrans.o dcasccfg.o dcasccff.o dccfuidh.o dccftsmp.o dccfpcmp.o dccfrsmp.o dccfenmp.o dccfprmp.o -lrt -lpthread -lnsl -lofstd -lm -lssl -lcrypto -ldl -ltiff -ljpeg -lz -lstdc++ -ldcmdata
So I get much less undefined reference

Code: Select all

ld libdcmnet.so 
ld: warning: cannot find entry symbol _start; not setting start address
libdcmnet.so: undefined reference to `request_init'
libdcmnet.so: undefined reference to `hosts_access'
libdcmnet.so: undefined reference to `request_set'
If I then add -lpng -lxml2 -lwrap I get no more undefined reference

I just tried all by chance but why is it not automatic ? (or just set in the makefile by default)
did I miss something ?

thank you

romain[/code]

Uli Schlachter
DCMTK Developer
Posts: 120
Joined: Thu, 2009-11-26, 08:15

#5 Post by Uli Schlachter »

valabregue wrote:I just tried all by chance but why is it not automatic ? (or just set in the makefile by default)
did I miss something ?[/code]
Static archives can't specify something like "I depend on these other libraries", that's only possibe with shared objects (.so).
Since the default is to build static archives, the Makefiles don't specify any library dependencies. Changing Makefile.def to build shared objects doesn't change this fact. So you are responsible for linking the needed libs to your final executable yourself.

Uli

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest