当我运行cxxtest时,我得到一个未定义的引用错误

时间:2010-04-14 06:30:56

标签: c++ unit-testing linker-errors 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 个答案:

答案 0 :(得分:1)

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

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

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

相关问题