Menu

#312 Error in using pre-compiled archive contatining log4cplus code

v1.1.3
closed
linker (3)
5
2015-02-19
2014-09-25
AshishGaur
No

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???

Discussion

  • Václav Haisman

    Václav Haisman - 2014-09-25
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -2,6 +2,7 @@
    
     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&&)':
    @@ -29,6 +30,7 @@
     /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. 
    
     
  • Václav Haisman

    Václav Haisman - 2014-09-25

    Try running your make with V=1 on command line and provide the line used by the LD linker command.

     
  • Václav Haisman

    Václav Haisman - 2014-09-25
    • labels: Linking, 5 --> linker
    • assigned_to: Václav Zeman
     
  • AshishGaur

    AshishGaur - 2014-09-25

    Did you mean " make V=1 obj/logtest " ?????? After this also getting same errors.

     
    • Václav Haisman

      Václav Haisman - 2014-09-25

      Yes. The point is to see the whole command line instead of just LD obj/logtest.

       
  • AshishGaur

    AshishGaur - 2014-09-25

    Its producing the same errors. I did clean the project also.

     
  • AshishGaur

    AshishGaur - 2014-09-25

    What does "make V=1" mean?

     
    • Václav Haisman

      Václav Haisman - 2014-09-25

      V=1 works with Automake generated Makefiles 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.

       
  • AshishGaur

    AshishGaur - 2014-09-29

    This is what i got after "make -n"

    echo "LD obj/test"
    g++ -ggdb -ffunction-sections -O0 -std=c++0x -pedantic -Wall -pthread -o obj/test obj/TestMuxDemux.o ../../mux_demux/obj/mux_demux.a ../../db/obj/db.a ../../net/obj/net.a ../../hal/obj/hal.a  -lmysqlclient -llog4cplus ../../lib/log.a
    

    I hope you were asking for this only.

     

    Last edit: Václav Haisman 2014-09-29
    • Václav Haisman

      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.

       
  • AshishGaur

    AshishGaur - 2014-09-30

    I made some changes as you said. The command line shows (on a test project):

    echo "LD obj/logtest"
    g++ -ggdb -ffunction-sections -O0 -std=c++0x -pedantic -Wall -pthread -o obj/logtest obj/logtest.o ../../../testClass/obj/db.a  ../../../lib/log.a -llog4cplus
    

    But still getting these errors:

    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
    
     

    Last edit: AshishGaur 2014-09-30
    • Václav Haisman

      Václav Haisman - 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 after g++ might help with debugging of this.

       
  • AshishGaur

    AshishGaur - 2014-09-30

    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:

    1. Copied my log.a to newer systems (This log.a was properly working on a system on which log4cplus libs were installed by following configure/make/make install)
    2. Copied my log.h to new system
    3. Copied log4cplus libs (liblog4cplus.a and liblog4cplus-1.1.so.9) to /usr/local/lib directory
    4. sed -i '$ a\/usr\/local\/lib' /etc/ld.so.conf
    5. ldconfig
    6. Tried to compile test code containing log functions

    This time i got the following errors (much less this time):

    CXX logtest.cpp
    LD obj/logtest
    //usr/local/lib/liblog4cplus.a(timehelper.o): In function `log4cplus::helpers::T                                                                             ime::gettimeofday()':
    timehelper.cxx:(.text+0x16c): undefined reference to `clock_gettime'
    //usr/local/lib/liblog4cplus.a(sleep.o): In function `log4cplus::helpers::sleep(                                                                             unsigned long, unsigned long)':
    sleep.cxx:(.text+0x1c): undefined reference to `clock_nanosleep'
    collect2: ld returned 1 exit status
    ../../../Makefile.rules:33: recipe for target 'obj/logtest' failed
    make: *** [obj/logtest] Error 1
    
     
  • Václav Haisman

    Václav Haisman - 2014-09-30

    Try linking with -lrt to get this function defined.

     
  • AshishGaur

    AshishGaur - 2014-10-01

    It worked. Thanks a lot.

     
  • Václav Haisman

    Václav Haisman - 2014-10-01
    • status: open --> closed
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.