编译器抛出错误“;“未定义符号”;在C程序中
在编译器抛出错误“;“未定义符号”;在C程序中,c,macos,unix,compiler-errors,header-files,C,Macos,Unix,Compiler Errors,Header Files,在test.c #include <stdio.h> #include "stdfn.h" int main(void) { printOut(10, "Hello, world!\n"); //bash("say hello world"); } 在这里,链接器无法找到printOut()函数的定义 您已经通过包含stdfn.h在test.c文件中包含了printOut()的声明,但是test.c中没有函数的定义fpr。定义见stdfn.c。因此,您需要将这两个
test.c
#include <stdio.h>
#include "stdfn.h"
int main(void)
{
printOut(10, "Hello, world!\n");
//bash("say hello world");
}
在这里,链接器无法找到
printOut()
函数的定义
您已经通过包含stdfn.h
在test.c
文件中包含了printOut()
的声明,但是test.c
中没有函数的定义fpr。定义见stdfn.c
。因此,您需要将这两个文件组合在一起以生成二进制文件
将编译行更改为
gcc test.c stdfn.c -o test -Wall
你可以做一个
gcc test.c stdfn.c -o test -Wall
(假定stdfn.c是printOut()定义所在的位置),以便将包含用户定义函数的文件链接到当前使用该函数的文件。可能的重复项请确保将函数声明保留在.h中,将定义保留在.c中。我明白了。h包括#包括“stdfn.c”为什么?
gcc test.c stdfn.c -o test -Wall