Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
编译器抛出错误“;“未定义符号”;在C程序中_C_Macos_Unix_Compiler Errors_Header Files - Fatal编程技术网

编译器抛出错误“;“未定义符号”;在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