在GCC中包含外部源文件时出现问题

在GCC中包含外部源文件时出现问题,c,gcc,C,Gcc,我对C比较陌生,所以请原谅我的问题太琐碎,尽管我在Stackoverflow中找不到任何有效的解决方案 我试图使用GCC编译一个源文件,同时提供另一个外部源文件(它具有我需要的实际方法) 下面是我尝试做的一个小例子: 这是我的主要源文件,hello.c #include <stdio.h> int main (void) { printTest(); return 0; } 这是我尝试使用的命令行: gcc -include method.c hello.c -o hello

我对C比较陌生,所以请原谅我的问题太琐碎,尽管我在Stackoverflow中找不到任何有效的解决方案

我试图使用GCC编译一个源文件,同时提供另一个外部源文件(它具有我需要的实际方法)

下面是我尝试做的一个小例子:

这是我的主要源文件,hello.c

#include <stdio.h>

int main (void)
{
printTest();
return 0;
}
这是我尝试使用的命令行:

 gcc -include method.c  hello.c -o hello -I./
我得到以下错误:

In file included from <command-line>:1:0:
./method.c: In function ‘printTest’:
./method.c:2:2: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
  printf ("Hello, world!\n");
  ^
包含在以下文件中:1:0:
/方法c:在函数“printTest”中:
./method.c:2:2:警告:内置函数“printf”的隐式声明不兼容[默认启用]
printf(“你好,世界!\n”);
^
更新: 让我困惑的是,如果我在hello.c中使用“#include”method.c”而不是使用GCC-include,它会工作得很好。我的琐碎想法让我假设include只是将代码放在主文件中,同时享受主源文件已经处理好的所有包含(例如stdio.h)

谢谢你的帮助
Uri

你需要在你的文件
方法中包含头
你需要在你的文件
方法中包含头
你需要在你的文件
方法.c
方法中包含头
你需要在你的文件
方法.c
中包含头
stdio.h
method.c
stdio.h
包含方法
printf

您必须在方法中包含
stdio.h
方法
stdio.h
包含方法
printf
您必须在方法
中包含
stdio.h
方法c
stdio.h
包含方法
printf

您必须在方法
中包含
stdio.h
。方法c
stdio.h
包含方法
printf

方法c
中包含
stdio.h
。您需要在
方法c
中包含
stdio.h
设置
printf
的声明。谢谢!它现在工作得很好!再次为这个琐碎的问题感到抱歉,我是新来的
method.c
中包含
stdio.h
的人。你需要在
method.c
中包含
stdio.h
来获得
printf
的声明。谢谢!现在工作得很好!再次为这个琐碎的问题感到抱歉在上,我是新加入
method.c
中的cInclude
stdio.h
的。你需要在
method.c
中加入
stdio.h
来获得
printf
的声明。谢谢!现在效果很好!再次为这个小问题道歉,我是新加入
method.c
中的cInclude
stdio.h
。你需要加入
stdio.h
method.c
中获取
printf
的声明。谢谢!它现在运行良好!再次为这个小问题感到抱歉,我是c新手
In file included from <command-line>:1:0:
./method.c: In function ‘printTest’:
./method.c:2:2: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
  printf ("Hello, world!\n");
  ^