warning: implicit declaration of function
You are using a function for which the compiler has not seen a declaration ("prototype") yet.
For example:
int main(){ fun(2, "21"); /* The compiler has not seen the declaration. */ return 0;}int fun(int x, char *p){ /* ... */}
You need to declare your function before main, like this, either directly or in a header:
int fun(int x, char *p);
The right way is to declare function prototype in header.
Example
main.h
#ifndef MAIN_H#define MAIN_Hint some_main(const char *name);#endif
main.c
#include "main.h"int main(){ some_main("Hello, World\n");}int some_main(const char *name){ printf("%s", name);}
Alternative with one file (main.c)
static int some_main(const char *name);int some_main(const char *name){ // do something}
When you do your #includes in main.c, put the #include reference to the file that contains the referenced function at the top of the include list.e.g. Say this is main.c and your referenced function is in "SSD1306_LCD.h"
#include "SSD1306_LCD.h" #include "system.h" #include <stdio.h>#include <stdlib.h>#include <xc.h>#include <string.h>#include <math.h>#include <libpic30.h> // http://microchip.wikidot.com/faq:74#include <stdint.h>#include <stdbool.h>#include "GenericTypeDefs.h" // This has the 'BYTE' type definition
The above will not generate the "implicit declaration of function" error, but below will-
#include "system.h" #include <stdio.h>#include <stdlib.h>#include <xc.h>#include <string.h>#include <math.h>#include <libpic30.h> // http://microchip.wikidot.com/faq:74#include <stdint.h>#include <stdbool.h>#include "GenericTypeDefs.h" // This has the 'BYTE' type definition#include "SSD1306_LCD.h"
Exactly the same #include list, just different order.
Well, it did for me.