My C program consists 3 files: common.h, common.c
and testmain.c
In common.h file I defined as:
/*global variables- variable declaration*/
extern int global_var; /*tell compiler do not
optimize at compile time*/
/*public interface function*/
extern int FUN1(int A);
...
-------------------------------------------
In common.c file I created as:
#include "C:\common.h" /*where the file locate*/
/* global variables -variable definition*/
int global_var;
/*public function definition*/
int FUN1(int A)
{
global_var = 20;
printf("global_var at FUNC is: %d",global_var);
return(A + global_var);
}
-----------------------------------------------
And in testmain.c file:
#include "common.h"
int main()
{
int result;
int global_var = 40; /*global variable define*/
int a = 50;
printf("Begin global_var is %d",global_var);
result = FUN1(a);
return 0;
}
I compiled my program without any error, but when
I link/build, it gave linker's errors as follows:
Linker error: undefined symbol global_var in module C:\common.c.....
Is anything related with wrong setting about the compiler(I use Borland C/C++ 5.1 compiler)?
You guys know what wrong with my prog?
I really appreciate your help!
DV007