当我编译下面的程序时,它给了我这个错误.
/tmp/ccwr6gsJ.o: In function 'main':
main.cL(.text+0xa): undefined reference to 'example'
collect2: error: Id returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
MAIN.C:
#include <stdio.h>
#include "includes.h"
int main()
{
int exampleInt = example();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
INCLUDES.H:
int example();
Run Code Online (Sandbox Code Playgroud)
includes.c:
#include "includes.h"
int example()
{
int i = 3;
return i;
}
Run Code Online (Sandbox Code Playgroud)
它似乎适用于Visual Studio,但不适用于Linux上的GCC
这很可能是构建错误,即您在错误的文件集上调用编译器,和/或不执行链接步骤.
尝试:
$ gcc -o myprog main.c example.c
Run Code Online (Sandbox Code Playgroud)
请注意,仅仅#include在C文件中不会以任何方式告诉编译器编译更多C文件.
| 归档时间: |
|
| 查看次数: |
79 次 |
| 最近记录: |