2017-02-24 155 views
1

我是新的CUnit,我試圖運行一個示例代碼來測試CUnit是否工作。 我有三個文件。CUnit錯誤:函數隱式聲明'CU_inizialize_registry'

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; 
    } 

而且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(); 
    } 

當我建立我收到一個警告和一個錯誤:

  • (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

CU_inizialize_registry怎麼了?我不明白。 你能幫我嗎? 感謝

更多信息: 的MacOS 10.12.3,Eclipse中,庫尼特2.1-3

回答

0

又是怎麼回事CU_initialize_registry代替CU_iniZialize_registry(T代替Z)?

+0

對我感到羞恥!我看到但沒有觀察到。 謝謝! –