Menu

linker errors: undefined reference to ...

Help
2005-03-14
2013-04-22
  • Markus Grunwald

    Markus Grunwald - 2005-03-14

    Hello,

    When I try to link my unittests I get a huge amount of linker errors:

    g++ -Wl,-rpath,/opt/qt/x86/qt3/lib -o unittest unittest.o    -L/opt/qt/x86/qt3/lib -L/usr/X11R6/lib -lcppunit -lqt-mt -lXext -lX11 -lm

    unittest.o(.text+0x16): In function `main':
    : undefined reference to `CppUnit::TextUi::TestRunner::TestRunner(CppUnit::Outputter *)'

    many like this one follow.
    I have no idea what could be wrong. Seems like g++ ignores the library.

    >g++ --version
    2.95.3

    >ls /usr/lib/libcppunit*
    /usr/lib/libcppunit-1.8.so.0      /usr/lib/libcppunit.la
    /usr/lib/libcppunit-1.8.so.0.0.0  /usr/lib/libcppunit.so
    /usr/lib/libcppunit.a

    Could anyone help me ?

     
    • Layne

      Layne - 2005-03-14

      g++ resolves linker errors based on the order the libraries, source files, and object files appear on the command line.  Unfortunately, it will produce errors like this if things are not quite in the "right" order.  You should try putting "-lcppunit" at the front of any other sources that are used during linking.

       
      • Markus Grunwald

        Markus Grunwald - 2005-03-15

        Thanks for your help, but if you look at the g++ line in my post:

        g++ -Wl,-rpath,/opt/qt/x86/qt3/lib -o unittest unittest.o -L/opt/qt/x86/qt3/lib -L/usr/X11R6/lib -lcppunit -lqt-mt -lXext -lX11 -lm

        -lcppunit is the first library that is linked. I even tried

        g++ -lcppunit ...

        without success...

        strange.

        Any other suggestions ?

         
        • Max Bernhardt

          Max Bernhardt - 2005-03-15

          Hi,
          you could try to link statically against libcppunit, i.e.: instead of -lcppunit add /usr/lib/libcppunit.a to your Linker Line.

          Another Question: could it be that libcppunit is compiled with a different compiler than the one you're using now (e.g. g++ >= 3.0)? g++ did change it's namemangling at least once in the last couple of years ...

          Cheers
          Max

           
        • Layne

          Layne - 2005-03-15

          It looks like unittest.o is the first thing that is linked.  I'd try putting -lcppunit even before the object file.  I'm not saying it will work, but it's my best guess at the moment.

           
    • Markus Grunwald

      Markus Grunwald - 2005-03-15

      It could be that my cppunit is compiled with gcc 3.x. I installed a rpm package for cppunit and am not sure. How can I find it out  ?

      But this takes me to my next problem: I can't compile cppunit with gcc 2.95.3. See my newest post for this...

      Thank you for your help,
      Markus

       

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.