未定义对 operator new 的引用

2022-01-11 00:00:00 gcc linker c++ cpputest

我正在尝试使用 cpputest 构建一个简单的单元测试可执行文件.我已经将 cpputest 框架构建到一个静态库中,现在正试图将它链接到一个可执行文件中.但是,由于相关代码,我被绑定到一个相当复杂的 Makefile 设置中.

I'm trying to build a simple unit test executable, using cpputest. I've built the cpputest framework into a static library, and am now trying to link that into an executable. However, I'm tied into a fairly complicated Makefile setup, because of the related code.

这是我的命令行:

/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 

我遇到了很多类似以下的错误:

I'm getting many errors like the following:

 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 吗?

I can't figure out what's causing this. Don't I get operator new for free with C++?

推荐答案

您的问题中可以处理的信息很少,但看起来有些代码使用了某种形式的 placement new,而那个特殊的 operator new 是 declared (编译器找到它并使用它编译代码),链接器找不到它的 定义.

There's very little information in your question to work from, but it looks like some code uses some form of placement new, and while that special operator new is declared (the compiler finds it and compiles the code using it), the linker can't find its definition.

(由于我的这个旧答案似乎仍然受到关注:有关声明与定义.)

相关文章