1

I am trying to learn cpputest, so went to the cpputest manual and copied the below code in my ubuntu 14.04lts laptop, and tried to make. I am new to make files, and I got a bunch of errors - how can I correct my code?

#include "CppUTest/TestHarness.h"
#include "CppUTest/TestOutput.h"

TEST_GROUP(FirstTestGroup)
{
};

TEST(FirstTestGroup, FirstTest)
{
    FAIL("Fail me!");
}

TEST(FirstTestGroup, SecondTest)
{
   STRCMP_EQUAL("hello", "world");
   LONGS_EQUAL(1, 2);
   CHECK(false);
}

That is test.cpp, and i have main like below named test_main.cpp

#include "CppUTest/CommandLineTestRunner.h"

int main(int argc, char** argv)
{
   return CommandLineTestRunner::RunAllTests(argc, argv);
}

The make file is:

all: test
export CPPUTEST_HOME=/usr/share/cpputest
CPPFLAGS += -I$(CPPUTEST_HOME)/include 
LD_LIBRARIES = -L$(CPPUTEST_HOME)/lib -lCppUTest -lCppUTestExt

test: test_main.o test.o
    g++ -o mytest test.o test_main.o
test_main.o: test_main.cpp 
    g++ -c test_main.cpp $(CPPFLAGS) 
test.o: test.cpp 
    g++ -c test.cpp  $(CPPFLAGS) $(LD_LIBRARIES)
    #g++ -C -o test_main.o test_main.cpp test.o test.cpp $(CPPFLAGS) 
    #g++ -o mytest tet_main.o test.o $(LD_LIBRARIES)

clean:
    rm -f *.o mytest

When I say make I get a bunch of errors.

Please help me in this regard

Rob
  • 26,989
  • 16
  • 82
  • 98
pradeep
  • 31
  • 3
  • It would probably be helpful to include more details about the errors you are getting. – APH Jul 01 '15 at 23:52
  • You should also consider if there are other tags that might be appropriate - you have added only one tag, and it does not appear to be frequently used. – APH Jul 01 '15 at 23:53
  • $ make g++ -o mytest test.o test_main.o test.o: In function `TEST_FirstTestGroup_FirstTest_Test::testBody()': test.cpp:(.text+0x9): undefined reference to `UtestShell::getCurrent()' test.cpp:(.text+0x53): undefined reference to `NormalTestTerminator::~NormalTestTerminator()' test.cpp:(.text+0x62): undefined reference to `NormalTestTerminator::~NormalTestTerminator()' test.o: In function `TEST_FirstTestGroup_SecondTest_Test::testBody()': test.cpp:(.text+0x81): undefined reference to `UtestShell::getCurrent()' .... goes on. – pradeep Jul 02 '15 at 15:35

1 Answers1

2
I changed the my makefile as follows: after the changes it worked

all: mytest
export CPPUTEST_HOME=/usr/local
CPPFLAGS += -I$(CPPUTEST_HOME)/include 
LD_LIBRARIES = -L$(CPPUTEST_HOME)/lib -lCppUTest -lCppUTestExt

mytest: test_main.o test.o
    g++ -g -o mytest test.o test_main.o $(LD_LIBRARIES)
test_main.o: test_main.cpp 
    g++ -g $(CPPFLAGS) -c test_main.cpp
test.o: test.cpp 
    g++ -g $(CPPFLAGS) -c test.cpp
clean:
    rm -f *.o mytest
pradeep
  • 31
  • 3