Reputation: 2452
I'm programming in C and my gcc compiler gives me the following warning in my function call in mySedondFile.c:
implicit declaration of function 'func'
The function prototype is declared in myfile.h
as:
void func(char*);
Function definition is in myfile.c
void func(char*x);
mySecondFile.c
contains:
#include "myfile.h"
func("Hello");
I'm missing why this would complain.
Upvotes: 3
Views: 25743
Reputation: 613562
That error is emitted because func
has not been declared at the point at which you call it.
It sounds like your header files aren't quite as you describe. Perhaps there is some conditional code. Maybe you have a header guard that is not working right. Another possibility is that you have got a letter case error and declared the function Func
but called it with func
. Very hard to say without seeing the actual files but you need to look for a reason why func
is not declared in the mySecondFile.c
translation unit.
To illustrate this a little more clearly, the following code:
int main(void)
{
func("Hello");
return 0;
}
results in this warning:
prog.c: In function ‘main’:
prog.c:3: warning: implicit declaration of function ‘func’
which is exactly as you report.
According to your description, your code includes a header file which declares func
. The compiler begs to differ with you and it remains for you to work out why func
is not declared.
Upvotes: 7