Search code examples
ceclipsemacoscunit

CUnit error: implicit declaration of function 'CU_inizialize_registry'


I'm new with CUnit, I'm trying to run a sample code to test if CUnit works. I have three files.

max.h

    #ifndef MAX_H_
    #define MAX_H_

    extern int maxi(int, int);

    #endif /* MAX_H_ */

max.c

    #include "max.h"

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

And Test_max.c

    #include <stdio.h>
    #include <CUnit/CUnit.h>
    #include <CUnit/Basic.h>

    #include "max.h"

    int init_suite(void)
    {
        return 0;
    }

    int clean_suite(void)
    {
        return 0;
    }

    void testMax(void)
    {
        CU_ASSERT(maxi(1,2) == 2);
        CU_ASSERT(maxi(3,2) == 3);
        CU_ASSERT(maxi(2,4) == 4);
    }

    int main()
    {
        CU_pSuite pSuite = NULL;

        if (CUE_SUCCESS != CU_inizialize_registry())
            return CU_get_error();

        pSuite = CU_add_suite("Suite di prova", init_suite, clean_suite);
        if (NULL == pSuite)
        {
            CU_cleanup_registry();
            return CU_get_error();
        }

        if (NULL == CU_add_test(pSuite, "Test max", testMax))
        {
            CU_cleanup_registry();
            return CU_get_error();
        }

        CU_basic_set_mode(CU_BRM_VERBOSE);
        CU_basic_run_tests();
        CU_cleanup_registry();
        return CU_get_error();
    }

When I build I receive a warning and an error:

  • (warning) warning: implicit declaration of function 'CU_inizialize_registry' is invalid in C99 [-Wimplicit-function-declaration] if (CUE_SUCCESS != CU_inizialize_registry())
  • (error) ld: symbol(s) not found for architecture x86_64

What's wrong with CU_inizialize_registry? I do not understand. Could you help me? Thanks

More info: MacOS 10.12.3, Eclipse, cunit 2.1-3


Solution

  • And what about CU_initialize_registry instead of CU_iniZialize_registry (t instead of z)?