2015-11-26 33 views
1

關於編譯suricata。 在Makefile中,當CFLAGS包裝「-Werror隱函數聲明」 我得到了錯誤:隱式聲明的函數和未定義的引用

detect-engine-siggroup.c: In function ‘SigGroupHeadFree’: 
detect-engine-siggroup.c:187:9: error: implicit declaration of function ‘_mm_free’ [-Werror=implicit-function-declaration] 
     SCFreeAligned(sgh->mask_array); 
     ^
detect-engine-siggroup.c: In function ‘SigGroupHeadBuildHeadArray’: 
detect-engine-siggroup.c:1715:5: error: implicit declaration of function ‘_mm_malloc’ [-Werror=implicit-function-declaration] 
    sgh->mask_array = (SignatureMask *)SCMallocAligned((cnt * sizeof(SignatureMask)), 16); 

當我在Makefile中刪除「-Werror隱函數聲明」,我就拿到了錯誤:

detect-engine-siggroup.o: In function `SigGroupHeadFree': 
/root/suricata/suricata-2.0.9/src/detect-engine-siggroup.c:187: undefined reference to `_mm_free' 
detect-engine-siggroup.o: In function `SigGroupHeadBuildHeadArray': 
/root/suricata/suricata-2.0.9/src/detect-engine-siggroup.c:1715: undefined reference to `_mm_malloc' 

注:_mm_free和_mm_malloc在UTIL-mem.h 定義然而,我其他的源文件中添加一些代碼,但不是在檢測引擎,siggroup.c和UTIL-MEM。 H。 有什麼問題?

在檢測引擎,siggroup.c(注意我已經在這裏刪除了一些冗餘代碼):

void SigGroupHeadFree(SigGroupHead *sgh) 
{ 
    if (sgh == NULL) 
     return; 

    SCLogDebug("sgh %p", sgh); 

    PatternMatchDestroyGroup(sgh); 

#if defined(__SSE3__) || defined(__tile__) 
    if (sgh->mask_array != NULL) { 
     /* mask is aligned */ 
     SCFreeAligned(sgh->mask_array); 
     sgh->mask_array = NULL; 
    } 
#endif 

    if (sgh->head_array != NULL) { 
     SCFree(sgh->head_array); 
     sgh->head_array = NULL; 
    } 

    if (sgh->match_array != NULL) { 
     detect_siggroup_matcharray_free_cnt++; 
     detect_siggroup_matcharray_memory -= (sgh->sig_cnt * sizeof(Signature *)); 
     SCFree(sgh->match_array); 
     sgh->match_array = NULL; 
    } 

    sgh->sig_cnt = 0; 

    if (sgh->init != NULL) { 
     SigGroupHeadInitDataFree(sgh->init); 
     sgh->init = NULL; 
    } 

    SCFree(sgh); 

    detect_siggroup_head_free_cnt++; 
    detect_siggroup_head_memory -= sizeof(SigGroupHead); 

    return; 
} 

在UTIL-mem.h(注意我已經刪除了一些在這裏冗餘代碼):

#ifndef __UTIL_MEM_H__ 
#define __UTIL_MEM_H__ 

#include "util-atomic.h" 

#if CPPCHECK==1 
#define SCMalloc malloc 
#define SCCalloc calloc 
#define SCRealloc realloc 
#define SCFree free 
#define SCStrdup strdup 
#define SCMallocAligned _mm_malloc 
#define SCFreeAligned _mm_free 
#else /* CPPCHECK */ 


#if defined(_WIN32) || defined(__WIN32) 
#include "mm_malloc.h" 
#endif 

#if defined(__tile__) 
/* Need to define __mm_ function alternatives, since these are SSE only. 
*/ 
#include <malloc.h> 
#define _mm_malloc(a,b) memalign((b),(a)) 
#define _mm_free(a) free((a)) 
#endif /* defined(__tile__) */ 

SC_ATOMIC_EXTERN(unsigned int, engine_stage); 

/* Use this only if you want to debug memory allocation and free() 
* It will log a lot of lines more, so think that is a performance killer */ 

/* Uncomment this if you want to print memory allocations and free's() */ 
//#define DBG_MEM_ALLOC 

#ifdef DBG_MEM_ALLOC 

#define SCFree(a) ({ \ 
    extern uint8_t print_mem_flag; \ 
    if (print_mem_flag == 1) {   \ 
     SCLogInfo("SCFree at %p", (a)); \ 
    }         \ 
    free((a)); \ 
}) 

#else /* !DBG_MEM_ALLOC */ 


#define SCFree(a) ({ \ 
    free(a); \ 
}) 

#if defined(__WIN32) || defined(_WIN32) 

#define SCFreeAligned(a) ({ \ 
    _mm_free(a); \ 
}) 

#else /* !win */ 

#define SCFreeAligned(a) ({ \ 
    _mm_free((a)); \ 
}) 

#endif /* __WIN32 */ 

#endif /* DBG_MEM_ALLOC */ 

#endif /* CPPCHECK */ 

#endif /* __UTIL_MEM_H__ */ 

#endif /* DBG_MEM_ALLOC */ 

#endif /* CPPCHECK */ 

#endif /* __UTIL_MEM_H__ */ 

/********************************************* ************************/

現在解決了這個問題,原因是遺忘到#include <pmmintrin.h> /* for SSE3 */

/******************************************** *************************/

+1

需要更多的信息,隱式聲明是由於缺少函數聲明,刪除該警告(或任何警告)不好,如果你這樣做,你只是隱藏問題。未定義的引用意味着,也沒有定義。你可以請張貼代碼嗎? –

+0

這似乎是你沒有包含正確的頭文件,並沒有鏈接到正確的庫。 –

+0

這兩個源文件可以編譯成功,當我沒有添加任何我的代碼在其他.c文件, – steve

回答

0

看起來您沒有正確包含util-mem.hSCFreeAligned似乎擴大到_mm_free,但_mm_free似乎並沒有擴大。看看頭文件_mm_free的定義似乎取決於被定義的__title__

然後,編譯器只看到_mm_free的調用,因爲_mm_free不存在,所以給出隱式原型。當然,在鏈接期間不會找到_mm_free