Error in using pre-compiled archive contatining log4cplus code
Logging Framework for C++
Brought to you by:
wilx
Hi,
I am relatively new to log4cplus. Recently i tried to use it with my code. But when i compile it i am getting following errors:
CXX logtest.cpp LD obj/logtest ../../../lib/log.a(log.o): In function `log4cplus::detail::macros_get_logger(log4cplus::Logger&&)': /usr/local/include/log4cplus/loggingmacros.h:106: undefined reference to `log4cplus::Logger::Logger(log4cplus::Logger&&)' ../../../lib/log.a(log.o): In function `CLog': /home/pi/TestLog/util/log/log.cpp:38: undefined reference to `log4cplus::initialize()' ../../../lib/log.a(log.o): In function `CLog::setProperty(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)': /home/pi/TestLog/util/log/log.cpp:71: undefined reference to `log4cplus::helpers::Properties::Properties(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int)' /home/pi/TestLog/util/log/log.cpp:72: undefined reference to `log4cplus::helpers::Properties::exists(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const' ../../../lib/log.a(log.o): In function `CLog::getProperty(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)': /home/pi/TestLog/util/log/log.cpp:81: undefined reference to `log4cplus::helpers::Properties::Properties(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int)' /home/pi/TestLog/util/log/log.cpp:82: undefined reference to `log4cplus::helpers::Properties::exists(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const' ../../../lib/log.a(log.o): In function `CLog::log(int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__va_list)': /home/pi/TestLog/util/log/log.cpp:180: undefined reference to `log4cplus::detail::get_macro_body_oss()' /home/pi/TestLog/util/log/log.cpp:180: undefined reference to `log4cplus::detail::macro_forced_log(log4cplus::Logger const&, int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*, int, char const*)' /home/pi/TestLog/util/log/log.cpp:185: undefined reference to `log4cplus::detail::get_macro_body_oss()' /home/pi/TestLog/util/log/log.cpp:185: undefined reference to `log4cplus::detail::macro_forced_log(log4cplus::Logger const&, int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*, int, char const*)' /home/pi/TestLog/util/log/log.cpp:190: undefined reference to `log4cplus::detail::get_macro_body_oss()' /home/pi/TestLog/util/log/log.cpp:190: undefined reference to `log4cplus::detail::macro_forced_log(log4cplus::Logger const&, int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*, int, char const*)' /home/pi/TestLog/util/log/log.cpp:195: undefined reference to `log4cplus::detail::get_macro_body_oss()' /home/pi/TestLog/util/log/log.cpp:195: undefined reference to `log4cplus::detail::macro_forced_log(log4cplus::Logger const&, int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*, int, char const*)' /home/pi/TestLog/util/log/log.cpp:200: undefined reference to `log4cplus::detail::get_macro_body_oss()' /home/pi/TestLog/util/log/log.cpp:200: undefined reference to `log4cplus::detail::macro_forced_log(log4cplus::Logger const&, int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*, int, char const*)' /home/pi/TestLog/util/log/log.cpp:210: undefined reference to `log4cplus::detail::get_macro_body_oss()' /home/pi/TestLog/util/log/log.cpp:210: undefined reference to `log4cplus::detail::macro_forced_log(log4cplus::Logger const&, int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*, int, char const*)' collect2: ld returned 1 exit status make: *** [obj/logtest] Error 1
I am sorry for the long message. But its very important for me to get out of it. I am getting these errors only when I am using a pre-compiled archive file (log.a, in my case) onto another Raspi, on this Raspi, i am not following "configure - make - make install" cycle. My seniors told me that it is possible but whenever I am trying to do it, it's throwing those errors.
I have copied the liblog4cplus-1.1.so.9 and liblog4cplus.a files into /usr/local/lib directory, as been told by the seniors.
Can you please help me out???
Diff:
Try running your
make
withV=1
on command line and provide the line used by theLD
linker command.Did you mean " make V=1 obj/logtest " ?????? After this also getting same errors.
Yes. The point is to see the whole command line instead of just
LD obj/logtest
.Its producing the same errors. I did clean the project also.
What does "make V=1" mean?
V=1
works with Automake generatedMakefile
s and it enables verbose mode which prints also command line parameters. If you are using a different build system, then simply find a way to get the whole linker command line. I suspect that your issues is the order of libraries on the command line.This is what i got after "make -n"
I hope you were asking for this only.
Last edit: Václav Haisman 2014-09-29
Yes, this is what I was asking about. The order of libraries on command line is significant. The library that provides some symbols needs to be specified after the library that consumes them. So change
-llog4cplus ../../lib/log.a
to../../lib/log.a -llog4cplus
.I made some changes as you said. The command line shows (on a test project):
But still getting these errors:
Last edit: AshishGaur 2014-09-30
Are you sure that you do not have some older log4cplus version library installed as well and that your linker is not picking up the old one instead of the newer one? Adding
-v
right afterg++
might help with debugging of this.I was not sure if my RasPi had older version of log4cplus so i decided to work on a fresh Raspi on which log4cplus was never installed or used. And I did follow these steps:
This time i got the following errors (much less this time):
Try linking with
-lrt
to get this function defined.It worked. Thanks a lot.