Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined reference to operator new

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

like image 736
mbyrne215 Avatar asked Sep 17 '10 13:09

mbyrne215


2 Answers

You probably need to link with the C++ support runtime library. This happens automatically when you invoke g++. On Linux, this is achieved by adding the -lstdc++ flag to the linker. You have to figure out how to do the same on your platform.

like image 106
zvrba Avatar answered Sep 19 '22 20:09

zvrba


Maybe you're calling gcc, the C compiler instead of g++, which is the C++ compiler.

like image 40
Shakaron Avatar answered Sep 22 '22 20:09

Shakaron