Skip to content

Stupid beginners problem #1794

Open
Open

Description

@FreekyFrank

I have taken the instructions in the manual literally and produced the following which clearly does not work. I am an novice with makefiles although I have written c for years so I guess my problem is stupid but it has me stumped.

Top level simple "makefile"

files = test.c AllTests.cpp

ed:
	emacs -mm $(files) makefile &

go:
	make -f MakefileCppUTest.mk

The real makefile (MakefileCppUTest.mk) I'm sure this is where the problem lies

CPPUTEST_HOME = /home/f/code/tdd-embeded-c-james-w-grenning/cpputest/

CPPFLAGS += -I$(CPPUTEST_HOME)/include

LD_LIBRARIES = -L$(CPPUTEST_HOME)/lib -lCppUTest -lCppUTestExt

AllTests.cpp

#include "CppUTest/TestHarness.h"

TEST_GROUP(FirstTestGroup)
{
};

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

test.c

#include "CppUTest/CommandLineTestRunner.h"

int main(int ac, char** av)
{
    return CommandLineTestRunner::RunAllTests(ac, av);
}

So please what do I do next?
Thanks

Activity

  1. FreekyFrank commented on May 12, 2024

    @FreekyFrank
    Author

    I should add I am not sitting on my hands but I am trying to learn about makefiles but I'm not in a position to add anything to the above.

  2. FreekyFrank commented on May 13, 2024

    @FreekyFrank
    Author

    Mmm.. Here is where I am now.

    I have two versions of CppUTest one downloaded via the James Grenning book (Which works):

    g++ -g -Wall -c test.c -o test.o
    g++ -g -Wall -c AllTests.cpp -o AllTests.o
    g++ -o AllTests AllTests.o test.o -Wl,-L/home/f/code/tdd-embeded-c-james-w-grenning/cpputest/lib -lCppUTest -lCppUTestExt
    ./AllTests
    
    AllTests.cpp:9: error: Failure in TEST(FirstTestGroup, FirstTest)
    	Fail me!
    
    .
    Errors (1 failures, 1 tests, 1 ran, 1 checks, 0 ignored, 0 filtered out, 0 ms)
    
    make: *** [makefile:50: end] Error 1
    

    and one cloned from github (Which dos not work)
    NOTE: I have cut out a large number of undefined references to shorten this section:

    g++ -g -Wall -c test.c -o test.o
    g++ -g -Wall -c AllTests.cpp -o AllTests.o
    g++ -o AllTests AllTests.o test.o -Wl,-L/home/f/code/cpputest/lib -lCppUTest -lCppUTestExt
    /usr/bin/ld: /home/fsmith/code/cpputest//lib/libCppUTest.a(lib_libCppUTest_a-CommandLineTestRunner.o): in function `_sub_I_00100_0':
    CommandLineTestRunner.cpp:(.text+0x1fae): undefined reference to `__gcov_init'
    /usr/bin/ld: /home/fsmith/code/cpputest//lib/libCppUTest.a(lib_libCppUTest_a-CommandLineTestRunner.o): in function `_sub_D_00100_1':
    CommandLineTestRunner.cpp:(.text+0x1fbd): undefined reference to `__gcov_exit'
    /usr/bin/ld: /home/fsmith/code/cpputest//lib/libCppUTest.a(lib_libCppUTest_a-CommandLineTestRunner.o):(.data.rel+0x20): undefined reference to `__gcov_merge_add'
    /usr/bin/ld: /home/fsmith/code/cpputest//lib/libCppUTest.a(lib_libCppUTest_a-JUnitTestOutput.o): in function `_sub_I_00100_0':
    JUnitTestOutput.cpp:(.text+0x2d72): undefined reference to `__gcov_init'
    ...
    ...
    ...
    TestFilter.cpp:(.text+0x7fe): undefined reference to `__gcov_exit'
    /usr/bin/ld: /home/fsmith/code/cpputest//lib/libCppUTest.a(lib_libCppUTest_a-TestFilter.o):(.data.rel+0x20): undefined reference to `__gcov_merge_add'
    collect2: error: ld returned 1 exit status
    make: *** [makefile:49: end] Error 1
    

    and they are clearly different

    The Grenning one is clearly much larger

    total 5144
    drwxrwxr-x  2 fsmith fsmith    4096 May  7 19:05 ./
    drwxrwxr-x 21 fsmith fsmith    4096 May  7 19:05 ../
    -rw-rw-r--  1 fsmith fsmith       0 May  7 19:04 .dirstamp
    -rw-rw-r--  1 fsmith fsmith 3032356 May  7 19:04 libCppUTest.a
    -rw-rw-r--  1 fsmith fsmith 2220422 May  7 19:05 libCppUTestExt.a
    

    than the one from github

    total 2668
    drwxrwxr-x  2 fsmith fsmith    4096 May 10 15:18 ./
    drwxrwxr-x 22 fsmith fsmith    4096 May 10 15:18 ../
    -rw-rw-r--  1 fsmith fsmith       0 May 10 15:18 .dirstamp
    -rw-rw-r--  1 fsmith fsmith 1469036 May 10 15:18 libCppUTest.a
    -rw-rw-r--  1 fsmith fsmith 1252558 May 10 15:18 libCppUTestExt.a
    

    The date stamps are for the date the files were downloaded, etc.
    Back to the makefile and on to some real tests and code

  3. basvodde commented on May 14, 2024

    @basvodde
    Member

    The undefined reference relates to having coverage enabled somewhere.

    How did you build after cloning ?

  4. FreekyFrank commented on May 14, 2024

    @FreekyFrank
    Author

    Hi Thanks for the response. I believe I followed the instructions given on the github page.
    The below is my latest makefile, on Linux, which is currently setup the way that works.

    .PHONY: clean go all
    
    files = test.c AllTests.cpp
    
    CC=g++
    CFLAGS=-I.
    SILENCE = @
    
    CPPUTEST_HOME = /home/f/code/tdd-embeded-c-james-w-grenning/cpputest/
    #CPPUTEST_HOME = /home/f/code/cpputest/
    
    DEPS =
    OBJ = AllTests.o test.o
    
    ed:
    	emacs -mm $(files) makefile &
    
    %.o: %.c $(DEPS)
    	$(CC) -c -o $@ $< $(CFLAGS)
    
    go:
    	reset
    	$(MAKE) AllTests
    	./AllTests
    
    all:
    	$(MAKE) clean
    	$(MAKE) AllTests
    
    AllTests: $(OBJ)
    	$(CC) -o $@ $^ $(CFLAGS) -Wl,$(LD_LIBRARIES)
    	./AllTests
    
    clean:
    	-rm *.o
    	-rm AllTests
    	-rm *~
    
    

    I'm beginning to think the best way forward is just to delete the version that does not work.
    Frank

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions