Hi everyone !
I have basic knowledge of c programming. I want to write a multiple c file project due to many functions in my program. so, i started to learn how to write learn multiple file program in c.
here is the example of three files which i compiled and tested on Dev-cpp compiler.it gives me the output 3. (I used Dev-cpp to learn how to write multiple c files).
main.c file :
#include <stdio.h> #include "other.h" int main (void) { printf("%d\n", getfavoritenumber()); return 0; }
other.h
#ifndef _OTHER_H_ #define _OTHER_H_ extern int getfavoritenumber(void); #endif
other.c
#include "other.h" int getfavoritenumber(void) { return 3; }
Now i same code i tested in keil. this gives following :
Build target 'Target 1' compiling main.c... linking... *** WARNING L1: UNRESOLVED EXTERNAL SYMBOL SYMBOL: GETFAVORITENUMBER MODULE: main.obj (MAIN) *** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL SYMBOL: GETFAVORITENUMBER MODULE: main.obj (MAIN) ADDRESS: 0010H Program Size: data=11.0 xdata=0 code=23 "test" - 0 Error(s), 2 Warning(s).
I don't know what to do? Please Help...
Thanks for your quick reply !
i have added the other.c file so keil compiled it successfully.
now i have made some changes to files.
main function calls ====> get_char function (declared and defined in vvv.h & vvv.c respectively)
get_char calls ====> getfavoritenumber function (declared and defined in other.h & other.c respectively)
main.c
#include <stdio.h> #include <p89v51rx2.h> #include "other.h" #include "vvv.h" void main (void) { P1=new_char(); while(1); }
vvv.h
#ifdef __VVV_H__ #define __VVV_H__ extern int new_char(void); #endif
vvv.c
#include "vvv.h" #include "other.h" int new_char(void) { return(getfavoritenumber()); }
#ifndef __OTHER_H__ #define __OTHER_H__ extern int getfavoritenumber(void); #endif
this time i have added all three files to my project (i.e. main.c,other.c & vvv.c)
now i got this warning...
Build target 'Target 1' compiling main.c... MAIN.C(9): warning C206: 'new_char': missing function-prototype compiling other.c... compiling vvv.c... linking... Program Size: data=9.0 xdata=0 code=31 "test" - 0 Error(s), 1 Warning(s).
i have included both header files in my main c file.
sorry.
my mistake.
main function calls ====> new_char function (declared and defined in vvv.h & vvv.c respectively)
new_char calls ====> getfavoritenumber function (declared and defined in other.h & other.c respectively)
Plz, tell me where u have gone wrong........