我们知道,在c语言中,函数的名字是全局可见的。举个例子来说,如果我们在fun.c中引用fun1.c中的一个函数,例如fun1(),哪么,在fun.c中无需声明fun1()便可以直接引用它。代码如下:
fun.h文件





fun.c文件




fun1();
}

fun1.h





fun1.c






main.c






编译 gcc -c *.c 连接并生成可执行文件gcc *.o -o funTest 运行./funTest 输出为“hello world”
如果将fun.c fun1.c及main.c改为fun.cpp,fun1.cpp以及main.cpp的话,在编译的时候就会出现
main.cpp:errro:"fun" was not decleared in this scope.
fun.cpp:error "fun1" was not decleared in this scope.
说明编译器在编译的时候找不到函数fun()和fun1()。因此,在main。cpp加入fun()声明void fun(),在fun。cpp中加入fun1的声明void fun1();这样便可以编译成功。