Menu

newbie g++ linker errors

Help
2003-10-13
2004-09-14
  • Rhys Ziemer

    Rhys Ziemer - 2003-10-13

    When attempting to compile code from the vague example that the cookbook proivdes, I get tons of linker errors.

    My compiling comands look like the following:
    g++ -c Complex.cpp
    g++ -c ComplexTestMain.cpp
    g++ -o ComplexTestMain ComplexTestMain.o Complex.o

    Any help would be greatly appreciated!
    Thanks.

    The errors look like the following:

    ComplexTestMain.o: In function `main':
    ComplexTestMain.o(.text+0x29): undefined reference to `CppUnit::TestSuite::TestSuite(basic_string<char, string_char_traits<char>, __default_alloc_template<true, 0> >)'
    ComplexTestMain.o(.text+0x48): undefined reference to `CppUnit::TestSuite::addTest(CppUnit::Test *)'
    ComplexTestMain.o(.text+0x5a): undefined reference to `CppUnit::TextTestResult::TextTestResult(void)'
    ComplexTestMain.o(.text+0x72): undefined reference to `CppUnit::TestSuite::run(CppUnit::TestResult *)'
    ComplexTestMain.o(.text+0x91): undefined reference to `CppUnit::operator<<(ostream &, CppUnit::TextTestResult &)'
    ComplexTestMain.o(.text+0xb0): undefined reference to `CppUnit::TextTestResult::~TextTestResult(void)'
    ComplexTestMain.o(.text+0xc1): undefined reference to `CppUnit::TestSuite::~TestSuite(void)'

     
    • Anonymous

      Anonymous - 2003-11-12

      Rhys,

      I was having the exact same problem and in fact just sent you an email asking if you had found the solution!  I'm also effectively a newbie to g++, having been away from the Unix platform for about 15 years.  But, with a bit more reading of the man pages I think I found the answer.

      The key thing is to tell the g++ compiler that you want to link with the library called libcppunit.a.  To do this you include the command line switch:

      -lcppunit

      Apparently the "lib" prefix and ".a" extension are assumed by the linker.

      If you still get errors then you need to figure out where libcppunit.a is and tell the linker to search that directory using the -L switch.  On my system, libcppunit.a is under /usr/local/lib so I use this:

      -L/usr/local/lib

      So let's say you have a program mytest.cpp and you want to create mytest.exe.  Then the full command line would be:

      g++ -o mytest mytest.cpp -L/usr/local/lib -lcppunit

      Hope this helps!

      - Terry

       
      • Ed Johnson

        Ed Johnson - 2004-09-14

        I think I have a similar problem.

        I am developing my app using cygwin and g++ on WindowsXP. My make file is in directory called 'Debug'.
        I have no LIB or INCLUDE environment variables set on my Windows box.

        Everything works fine on Windows with the following command line:

        g++ -I../  -o prsvm.exe $(OBJS) -L../cppunit/lib -lcppunit

        However, when I ftp this to a Solaris box, I get this following output, though there are 100's more errors:

        Building target: prsvm.exe
        g++ -I../  -o prsvm.exe ../Client.cpp ../HivClient.cpp ../HivPreProcessor.cpp ../HivWorkUnit.cpp ../Instruction.cpp ../Kernel.cpp ../PreProcessor.cpp ../WorkUnit.cpp ../string_tokenizer/StringTokenizer.cpp  ../unit_tests/TestClient.cpp ../unit_tests/TestHivPreProcessor.cpp ../unit_tests/TestHivWorkUnit.cpp ../unit_tests/TestInstruction.cpp ../unit_tests/TestRun.cpp ../unit_tests/TestWorkUnit.cpp -L../cppunit/lib -lcppunit
        /tmp/ccGnVnI3.o(.text+0x23): In function `main':
        undefined reference to `CppUnit::TextTestRunner::TextTestRunner[in-charge](CppUnit::Outputter*)'
        /tmp/ccGnVnI3.o(.text+0x37): In function `main':
        undefined reference to `CppUnit::TestRunner::addTest(CppUnit::Test*)'
        /tmp/ccGnVnI3.o(.text+0x4b): In function `main':
        undefined reference to `CppUnit::TestRunner::addTest(CppUnit::Test*)'
        /tmp/ccGnVnI3.o(.text+0x5f): In function `main':
        undefined reference to `CppUnit::TestRunner::addTest(CppUnit::Test*)'
        /tmp/ccGnVnI3.o(.text+0x73): In function `main':
        undefined reference to `CppUnit::TestRunner::addTest(CppUnit::Test*)'
        /tmp/ccGnVnI3.o(.text+0xc2): In function `main':
        undefined reference to `CppUnit::TextTestRunner::run(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, bool, bool)'
         

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.