GCC 컴파일러로 신비한 상황에 처했습니다. 그래서이있어 다음과 같은 파일 :GCC : 이전 C 코드로 작업 할 때 링커 오류가 발생했습니다.
//main.cpp
#include "mleak_cpp.h"
int main(int argc, char* argv[])
{
foo();
__memory_malloc(10,"hello",5);
return 0;
}
//mleak_cpp.h
......
void foo(void);
void* __memory_malloc(size_t size, const char* file, int line);
//mleak_cpp.cpp
//definitions of the functions;
void foo(void){printf("foo\n");
void* __memory_malloc(size_t size, const char* file, int line){
printf("%s,%d\n",file,line);
InitDoubleLinkList();
void* p = malloc(size);
if(p == NULL)
return NULL;
__DuLinkList* pListNode;
pListNode = (__DuLinkList*)malloc(sizeof(__DuLinkList));
pListNode->address = p;
pListNode->memorysize = size;
pListNode->file = file;
pListNode->line = line;
InsertBlockToList(pListNode);
return p;
}
들어 어떤 이유로, void foo (void)에 대한 호출은 괜찮지 만 "__memory_malloc"에 대한 호출은 링커 오류 인 "정의되지 않은 참조"로 중단됩니다. 서로 다른 행동을 일으키는 두 기능의 차이점은 무엇입니까?
는 내가 "#INCLUDE"지시문에 '통근 C "를 추가하는 시도, 그래서 MAIN.CPP 읽
extern "C"{
#include "mleak_cpp.h"
}
와 함수의 선언하기 전에"통근 "키워드를 추가하고,이 시간을 동일한 오류로 "foo()"에 대한 호출도 실패합니다.
나는 당신이 잘못된 위치에 extern "C"
을 배치하고 너희들
정확한 오류 메시지 대신 뚜렷한 오류 메시지를 게시해야합니다. –