I was looking at this question here : How do I use extern to share variables between source files? followed the manual . but still I get Linker errors ... Would love to get some help and explanation why it happens..
I have 2 .c files and one header file :
------check.h----
#ifndef check
#define check
extern int num;
#endif
----check.c----
#include "check.h"
#include <stdio.h>
int func(int x, int y)
{
int z = x+y;
return z;
}
void printnum()
{
num++;
printf("%d",num);
}
----ynnynyny.c----
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
#include "check.h"
#include "check.c"
int num = 10;
int main()
{
printf("num before is : %d\n",num);
printnum();
printf("num now is : %d",num);
getchar();
return 0;
}
I keep getting these errors :
1> ynnyny.c
1> check.c
1> Generating Code...
1>ynnyny.obj : error LNK2005: _func already defined in check.obj
1>ynnyny.obj : error LNK2005: _printnum already defined in check.obj
I wrote the #ifndef stuff and also the extern declaration, so what Is the problem?
thanks!