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)'
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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:
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:
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)'
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
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: