对操作符new的未定义引用 [英] Undefined reference to operator new

查看:570
本文介绍了对操作符new的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用cpputest构建一个简单的单元测试可执行文件。我已经建立了cpputest框架到一个静态库,我现在正试图链接到一个可执行文件。但是,由于相关代码,我被绑定到一个相当复杂的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应用程序/ UnitTests / lib / libcpputest.a -Wl, -  end-group -lm 



我收到很多错误,例如:

  Application / UnitTests / lib / libcpputest.a(CommandLineTestRunner.o):在函数`CommandLineTestRunner :: parseArguments(TestPlugin *)'中:
Application / UnitTests / cpputest / src / CppUTest / .objs /。 ./CommandLineTestRunner.cpp:114:未定义引用`operator new(unsigned int,char const *,int)'


$ b b

我无法弄清楚造成这种情况的原因。

解决方案

在你的问题中有很少的信息可以工作,但它看起来像一些代码使用某种形式的 placement new ,而操作符new / strong>(编译器找到它并使用它编译代码),链接器找不到 定义


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.

This is my command line:

/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)'

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

解决方案

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.

这篇关于对操作符new的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆