CUnit : undefined reference to `CU_assertImplementation'

4.8k Views Asked by At

compiled it using : cc -o test testtest.c -lcunit , but still cant run the tests properly. they crash for some reason :)

I'm working on a project and i have recently convinced myself that i should continue in an testdriven approach. Mainly because the project itself is growing and i want proof of that all functions work.

But i bump into some problems while doing a cunit tutorial. http://cunit.sourceforge.net/doc/writing_tests.html

This is my cunit test file :

#include <CUnit/CUnit.h>

main(){
    test_maxi();
}

int maxi(int i1, int i2){
      return (i1 > i2) ? i1 : i2;
}

void test_maxi(void){
  CU_ASSERT(maxi(0,2) == 2);
  CU_ASSERT(maxi(0,-2) == 0);
  CU_ASSERT(maxi(2,2) == 2);
 }

i get these errors when i try to compile it :

testtest.c:(.text+0x62): undefined reference to CU_assertImplementation' testtest.c:(.text+0x9b): undefined reference toCU_assertImplementation' testtest.c:(.text+0xd5): undefined reference to `CU_assertImplementation' collect2: ld returned 1 exit status

I used google and i think it got something todo with linking? But i didnt get much help out of it.

Best Regards Rickard

1

There are 1 best solutions below

0
On

Solution by OP.

compiled it using:

gcc -Wall -o test basicexample.c -lcunit