我正在尝试使用 cpputest 构建一个简单的单元测试可执行文件。我已经将 cpputest 框架构建到一个静态库中,现在正试图将它链接到一个可执行文件中。但是,由于相关代码,我被绑定(bind)到一个相当复杂的 Makefile 设置中。
这是我的命令行:
/usr/bin/qcc -V4.2.4,gcc_ntoarmle_acpp-ne -lang-c++ -O2 -g -g -o Application/UnitTests/Tests/symbols/UnitTestExe -Wl,--start-group Application/UnitTests/Tests/../.objs/main.o Application/UnitTests/lib/libcpputest.a -Wl,--end-group -lm
我遇到了很多类似以下的错误:
Application/UnitTests/lib/libcpputest.a(CommandLineTestRunner.o): In function `CommandLineTestRunner::parseArguments(TestPlugin*)':
Application/UnitTests/cpputest/src/CppUTest/.objs/../CommandLineTestRunner.cpp:114: undefined reference to `operator new(unsigned int, char const*, int)'
我不知道是什么原因造成的。我不是用 C++ 免费获得 operator new 吗?
最佳答案
您可能需要链接到 C++ 支持运行时库。这在您调用 g++ 时会自动发生。在 Linux 上,这是通过将 -lstdc++
标志添加到链接器来实现的。你必须弄清楚如何在你的平台上做同样的事情。
关于c++ - 未定义对 operator new 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3735804/