log4cplus linker error

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
zappy1
Posts: 28
Joined: Fri, 2008-06-27, 11:27

log4cplus linker error

#1 Post by zappy1 »

Hi all,

I apologize in advance if I posted in a wrong place (I still hope not).

For reasons not depending on my will, I have to use dcmtk-3.6.0 in a 32 bit WindowsXP environment :( with MSYS-1.0.11 and mingw (latest stable version, 2013072200 or so). The good news is I won't have to replicate the work on other machines (so one has not to care too much about portability). The bad news is that I constantly get a nasty error when linking against the unavoidable dcmdata library.
The compilation line I use is:

Code: Select all

g++  project.cxx   -DHAVE_CONFIG_H -Wno-deprecated -L/usr/local/lib -mwindows -lfltk -lole32 -luuid -lcomctl32 -static -I/usr/local/include -I/include -L/usr/local/lib -o project -llog4cplus -lz -lws2_32 -lwsock32 -lnetapi32 -lofstd -loflog -ldcmdata -ldcmimgle  -lpthread -lm

I added "-llog4cplus" after compiling and installing on the system the package log4cplus-1.0.4.3, since it was referenced by compiler messages, but at the end I still get the same sad information:

Code: Select all

C:/msys/1.0/local/lib\libdcmdata.a(dcfilefo.o):dcfilefo.cc:(.text+0x9bd): undefined reference to `log4cplus::Logger::isEnabledFor(int) const'
C:/msys/1.0/local/lib\libdcmdata.a(dcfilefo.o):dcfilefo.cc:(.text+0x9d1): undefined reference to `log4cplus::Logger::~Logger()'
C:/msys/1.0/local/lib\libdcmdata.a(dcfilefo.o):dcfilefo.cc:(.text+0xd3b): undefined reference to `log4cplus::Logger::forcedLog(int, OFString const &, char const*, int, char const*) const'

[...] (similar messages repeat a bunch of times)

C:/msys/1.0/local/lib\libdcmdata.a(dcfilefo.o):dcfilefo.cc:(.text+0x731f): more undefined references to `log4cplus::Logger::~Logger()' follow
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:/msys/1.0/local/lib\libdcmdata.a(dcfilefo.o): bad reloc address 0x8 in section `.text$_ZN9DcmObject5setVRE6DcmEVR[__ZN9DcmObject5setVRE6DcmEVR]'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
The same code (under Windows 7, with dcmtk-3.5.4 and no reference to the log4cplus library) compiles straight well on another machine, so I guess I have something wrong or missing on my command line, but I can't figure what. I would appreciate any suggestion.

Thank you for your feedback.

Michael Onken
DCMTK Developer
Posts: 2048
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: log4cplus linker error

#2 Post by Michael Onken »

Hi,

there is no need to link against log4cplus since the oflog library in DCMTK is an integrated version of it and contains everything you need.

However, I guess you get the same messages when you leave out -llog4cplus?

I am always confused about the linker order for the libraries (simple to complex one or vice-versa) , but you you please try to reverse the current DCMTK library linker order, i.e. link -ldcmimgle -ldcmdata -loflog -lofstd?

Best,
Michael

zappy1
Posts: 28
Joined: Fri, 2008-06-27, 11:27

Re: log4cplus linker error

#3 Post by zappy1 »

Thank you for your answer...
there is no need to link against log4cplus since the oflog library in DCMTK is an integrated version of it and contains everything you need.
Yes, I imagined that after looking at the sources, but it was worth a try.
However, I guess you get the same messages when you leave out -llog4cplus?
Of course.
I am always confused about the linker order for the libraries (simple to complex one or vice-versa) , but you you please try to reverse the current DCMTK library linker order, i.e. link -ldcmimgle -ldcmdata -loflog -lofstd?
Good news: the log4cplus error has gone. :)
Bad news: another linking error popped up... :(

Code: Select all

C:/msys/1.0/local/lib\libdcmdata.a(dcuid.o):dcuid.cc:(.text+0x37): undefined reference to `WASStartup@8'
C:/msys/1.0/local/lib\libdcmdata.a(dcuid.o):dcuid.cc:(.text+0x50): undefined reference to `gethostname@8'
C:/msys/1.0/local/lib\libdcmdata.a(dcuid.o):dcuid.cc:(.text+0x65): undefined reference to `gethostbyname@4'
C:/msys/1.0/local/lib\libdcmdata.a(dcuid.o):dcuid.cc:(.text+0x86): undefined reference to `WSACleanup@0'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:/msys/1.0/local/lib\libdcmdata.a(dcuid.o): bad reloc address 0x0 in section `.data'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
The error presents itself always: I tried to insert -luuid outside L/R and between the four dcmtk calls -ldcmimgle -ldcmdata -loflog -lofstd, but nothing changes.
May I ask here for a hint (even if it seems rather off-topic with the title)?!

zappy1
Posts: 28
Joined: Fri, 2008-06-27, 11:27

Re: log4cplus linker error

#4 Post by zappy1 »

Bad news: another linking error popped up...
OK, the error got solved!
I made several changes in the order (say educated guesses) and finally I was able to compile cleanly with:

Code: Select all

g++  project.cxx   -DHAVE_CONFIG_H -Wno-deprecated -L/usr/local/lib -mwindows -lole32 -luuid -lcomctl32 -static -lfltk -I/usr/local/include -I/usr/local/include/log4cplus -I/include -L/usr/local/lib -o project -lnetapi32  -ldcmimgle -ldcmdata  -loflog -lofstd -lpthread -lm -lwsock32  -lz -lws2_32
At this point it's just a wonder of mine if there is a clear algorithm which gives the order of inserting library calls on the command line (for any libraries which could be useful in the future) or one has to make a lot of successive tries?! For dcmtk libraries I understand it's from complex to simple, but what about the others?

Michael Onken
DCMTK Developer
Posts: 2048
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: log4cplus linker error

#5 Post by Michael Onken »

Hi,
zappy1 wrote: At this point it's just a wonder of mine if there is a clear algorithm which gives the order of inserting library calls on the command line (for any libraries which could be useful in the future) or one has to make a lot of successive tries?! For dcmtk libraries I understand it's from complex to simple, but what about the others?
It's the same rule for other libraries. If a library (A) depends on other libraries (B,C,D), then the linker order is A,B,C,D, i.e. the ones that do not depend on other ones go to the very right side (end of linker order), where the ones that depend on most other ones will end up on the very left (i.e. beginning) in the linker order.

That is why you also had to shift the Windows default libraries to the right since nearly all code requires those libraries on Windows.

A good way to identify the correct linker order for DCMTK libraries is to look into a CMakeLists.txt file inside one of the apps folders, where you can see the linker order used within DCMTK. The linker order for DCMTK versus Windows standard libraries can be found in the top level CMakeLists.txt file (IIRC).

HTH,
Michael

zappy1
Posts: 28
Joined: Fri, 2008-06-27, 11:27

Re: log4cplus linker error

#6 Post by zappy1 »

OK, I hope that should cover most of my basic compilation needs for the moment.
Thank you very much for your time & answers.

Z.B.

rasoul
Posts: 1
Joined: Mon, 2018-07-23, 14:07

Re: log4cplus linker error

#7 Post by rasoul »

Hi every one
I am new with DCMTK and I faced with similar errors. How can I fix it?
I do not understand how you solve this problem.
thanks...

Michael Onken
DCMTK Developer
Posts: 2048
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: log4cplus linker error

#8 Post by Michael Onken »

Sorry, you find all information above, considering the level of detail your question provides...

Best,
Michael

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 1 guest