2

I am having a problem when trying to use CPPUTest to test my library.

Everything was fine until i included Eigen library to handle matrix processing. When i tried to build with g++, Eigen library kept throwing errors:

  • /eigen3/Eigen/src/Core/util/Memory.h:270:41 error: 'ptr' does not name a type

  • /eigen3/Eigen/src/Core/CoreEvaluators.h:1655:12 error: expected type-specifier before 'static_cast'

  • /eigen3/Eigen/src/Core/PlainOBjectBase.h:137:5 error: declaration of 'operator new' as non-function

If Eigen or CPPUTest runs separately, no error is output.

My guess is the two libraries have conflicts at some point.

Really need some helps here. Big thanks.

Edit 1: This is my Makefile:

CXX = g++ -std=c++0x -lstdc++ CXXFLAGS = -g -Wall -static -fprofile-arcs -ftest-coverage -I./ -I$(CPPUTEST_HOME)/include LDFLAGS = -L./ -L$(CPPUTEST_HOME)/lib -lCppUTest -lCppUTestExt -pthread CPPUTEST_HOME = ./cpputest/workspace/install USER_CFLAGS = -I /usr/local/include/eigen3 TARGET = MyLibrary SRCS = MyLibrary.cpp MyLibraryTest.cpp OBJS = $(SRCS:.cpp=.o) all: $(TARGET) $(TARGET): $(OBJS) $(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) $(OBJS): $(SRCS) $(CXX) -c $(CXXFLAGS) $^ %.o: %.cpp $(CXX) -c $(CXXFLAGS) $<
.PHONY: clean clean: rm -f $(TARGET) $(OBJS) *.gcno *.gcov ~ find . -name ".gcda" | xargs -r r

6
  • Can you specify which version of Eigen and CPPUTest you're using? A full minimal reproducible example would also be helpful... Commented Dec 28, 2016 at 8:45
  • I'm using the latest versions of both libraries: Eigen 3.3.1 and CPPUTest 3.8 Commented Dec 28, 2016 at 8:50
  • Can I see the command line used to build the .cpp file that triggered these errors? Commented Dec 28, 2016 at 18:42
  • Did you try including Eigen before CPPUTest? Commented Dec 29, 2016 at 1:33
  • Yes, i did. Still doesn't work. Commented Dec 29, 2016 at 8:54

1 Answer 1

1

It appears that CppUTest defines a macro new: https://github.com/cpputest/cpputest/blob/master/include/CppUTest/MemoryLeakDetectorNewMacros.h#L76

When I #include <Eigen/Core> before #include <CppUTest/TestHarness.h>, I don't get the error you reported (did no further testing, though). Alternatively, you can #undef new after including CppUTest or define CPPUTEST_MEM_LEAK_DETECTION_DISABLED before including CppUTest (that will of course disable leak detection).

The offending line in Eigen is using the placement-new operator (i.e., it does not allocate memory itself), and it's syntax is what throws CppUTest's new macro off.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.