2015-09-25 111 views
1

當我編譯下面的程序時,它給了我這個錯誤。GCC錯誤,但VS沒有錯誤

/tmp/ccwr6gsJ.o: In function 'main': 
main.cL(.text+0xa): undefined reference to 'example' 
collect2: error: Id returned 1 exit status 

MAIN.C:

#include <stdio.h> 

#include "includes.h" 

int main() 
{ 
    int exampleInt = example(); 

    return 0; 
} 

INCLUDES.H:

int example(); 

includes.c:

#include "includes.h" 

int example() 
{ 
    int i = 3; 

    return i; 
} 

似乎在Visual Studio中,但沒有上下班GCC on Linux

回答

6

這很可能是一個構建錯誤,即你在錯誤的文件集上調用編譯器,和/或不執行鏈接步驟。

嘗試:

$ gcc -o myprog main.c example.c 

注意,在C文件中僅僅#include不以任何方式告訴編譯器來編譯多個C文件。

+0

它的工作原理!謝謝! – ChrisK