請教下各位大神,這是什么原因造成的?
代碼(code):
#include <stdio.h>
int main()
{
int a1=32;
int a2=51;
int maxNum=max(a1,a2);
printf("the max value is %d",maxNum);
return 0;
}
錯誤報告(error report):
trugle@strugle-virtual-machine:~/workspace/les1/les2$ gcc max.c hello.c o- main.out
hello.c: In function ‘main’:
hello.c:8:20: warning: implicit declaration of function ‘max’ [-Wimplicit-function-declaration]
? ? 8 |? ? ? ? ?int maxNum=max(a1,a2);
? ? ? |? ? ? ? ? ? ? ? ? ? ^~~
gcc: error: -E or -x required when input is from standard input
2022-11-25
//?定義max.c源文件,以下是文件內容 int?max(int?a,?int?b)?{ ????return?a?>?b???a?:?b; } //?定義max.h頭文件,文件內容 int?max(int,?int); //?在main函數所在文件中,要加入#include?"max.h",而且要和main文件在一個文件夾內 //?編譯文件gcc?-c?max.c?-o?max.o //?生成最終文件gcc?max.o?main.c?-o?main.out //?main.c就是包含main函數的文件,可以根據自己命名文件來修改 //?講課視頻中不出現編譯問題,就是因為編譯器不同造成的2022-08-12
你的max函數沒有聲明,可以選擇在main函數之前把max寫上,或者在頭文件里引用max.c或者編譯后的max.h