views:

91

answers:

1
./cxxtest/cxxtestgen.py -o tests.cpp --error-printer DrawTestSuite.h
g++ -I./cxxtest/ -c tests.cpp
g++ -o tests tests.o Color.o
tests.o: In function `DrawTestSuite::testLinewidthOne()':
tests.cpp:(.text._ZN13DrawTestSuite16t… undefined reference to `Linewidth::Linewidth(double)'
tests.cpp:(.text._ZN13DrawTestSuite16t… undefined reference to `Linewidth::draw(std::basic_ostream<char… std::char_traits<char> >&)'
collect2: ld returned 1 exit status
make: *** [tests] Error 1// DrawTestSuite.h

DrawTestSuite.h contains the unit-test and The test function calls on Linewidth.h to execute the constructer and member function draw.

I have #include "Linewidth.h"in DrawTestSuite.h.

+1  A: 

"Undefined reference" is a linker error when a function has been properly declared and used, but the definition has not been included when linking.

You need to link with Linewidth.o, which is the object file from compiling Linewdith.cpp and the likely location where those functions are implemented.

I'm not familiar with cxxtest to know how it expects you to specify that dependency, but I suspect it only requires a simple declaration.

Roger Pate
+1. 3rd line should be `g++ -o tests tests.o Color.o Linewidth.o`
Draco Ater
@Draco: That is make showing the command it's executing, and the makefile could be generated. (If it's not, simply include the appropriate "tests: Linewidth.o" rule, which adds "Linewidth.o" as a dependency.)
Roger Pate
I know that it's makefile :)
Draco Ater