tags:

views:

131

answers:

2

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

+1  A: 

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.

sbi
I'm not sure what other info to add. The code is really simple; it doesn't redefine 'new', so I can't figure why the linker can't find it from the standard library.
mbyrne215
@mbyrne215: You could add the simplest code that reproduces this. The error message clearly mentions an `operator new(unsigned int, char const*, int)` (called from `CommandLineTestRunner::parseArguments(TestPlugin*)`), which is clearly not the standard version of that operator.
sbi
You're right; I got so hung up looking for why the standard libs weren't working, I didn't look through the 3rd party library closely. It was secretly redefining new. I removed that part and all is good. Thanks.
mbyrne215
+1  A: 

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 -lstdc++ flag to the linker. You have to figure out how to do the same on your platform.

zvrba