2010-04-14 83 views
0

我不确定要理解我得到的未定义的引用。当我运行cxxtest时,我得到一个未定义的引用错误

./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包含单元测试和测试函数调用Linewidth.h来执行构造函数和成员函数的绘制。

我在DrawTestSuite.h中有#include "Linewidth.h"

回答

1

当未正确声明和使用函数时,“未定义的引用”是链接器错误,但链接时定义未包含。

您需要链接Linewidth.o,它是编译Linewdith.cpp时的对象文件以及实现这些函数的可能位置。

我不熟悉cxxtest知道它期望你如何指定依赖关系,但我怀疑它只需要一个简单的声明。

+1

+1。第三行应该是'g ++ -o tests tests.o Color.o Linewidth.o' – 2010-04-14 06:58:45

+0

@Draco:这就是显示正在执行的命令,并且可以生成makefile。 (如果不是,只需包含适当的“tests:Linewidth.o”规则,即添加“Linewidth.o”作为依赖项。) – 2010-04-14 07:01:35

+0

我知道它是makefile :) – 2010-04-14 07:12:46

相关问题