gpt4 book ai didi

c++ - 当我运行 cxxtest 时,出现 undefined reference 错误

转载 作者:行者123 更新时间:2023-11-28 08:29:54 24 4
gpt4 key购买 nike

我不确定是否理解我收到的 undefined reference 。

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

最佳答案

“ undefined reference ”是一个链接器错误,当一个函数已经被正确地声明和使用,但是在链接时还没有包含定义。

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

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

关于c++ - 当我运行 cxxtest 时,出现 undefined reference 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2635300/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com