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

C++ 当我运行cxxtest时,我得到一个未定义的引用错误,c++,unit-testing,linker-errors,cxxtest,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… undefi

我不确定是否理解我得到的未定义引用

./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
/cxtest/cxtestgen.py-o tests.cpp--打印机DrawTestSuite.h出错
g++-I./cxtest/-c tests.cpp
g++-o测试tests.o颜色.o
tests.o:在函数“DrawTestSuite::testLinewidthOne()”中:
tests.cpp:(.text._ZN13DrawTestSuite16t…对'Linewidth::Linewidth(double)'的未定义引用
tests.cpp:(.text.\u ZN13DrawTestSuite16t…对'Linewidth::draw(std::basic_ostream&')的未定义引用
collect2:ld返回了1个退出状态
make:**[tests]错误1//DrawTestSuite.h
h包含单元测试,测试函数调用Linewidth.h来执行构造函数和成员函数draw

我在DrawTestSuite.h中包含了“Linewidth.h”。

如果函数已正确声明和使用,但链接时未包含定义,则“未定义引用”是链接器错误

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


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

+1.第3行应该是
g++-o tests.o Color.o Linewidth.o
@Draco:这是make,显示它正在执行的命令,并且可以生成makefile。(如果不是,只需包含适当的“tests:Linewidth.o”规则,该规则将“Linewidth.o”添加为依赖项。)