当我运行 cxxtest 时,出现未定义的参考错误

发布于 2024-08-29 00:10:58 字数 693 浏览 1 评论 0原文

我不确定是否理解我得到的未定义的参考。

./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来执行构造函数和成员函数draw。

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

I'm not sure to understand the undefined reference I am getting.

./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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰雪梦之恋 2024-09-05 00:10:58

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

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

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

"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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文