Help needed with #include problems

Frank Swarbrick swarbric at tramp.Colorado.EDU
Wed May 18 13:02:06 AEST 1988


In article <28400001 at ntvax> john at ntvax.UUCP writes:
:
:I am using Turboc 1.5 and am having problems linking files. I am writing
:a large application (over 64k) and am having trouble breaking up the file.
:The question is this, when I #include stdio, stdlib etc in multiple source
:modules the compiler and linker have no problems, however, this is not the 
:case when i #include my own header files. The compile goes ok but the linker 
:gives me the following error - "variable name here" is duplicated in module
:"source module name here" . This only occurs for my specfic header files not
:the system (stdio, etc). What can I do to get around this problem. Using 
:extern may help but the header file is very large. 

Variables can only be declaired once without the "extern" keyword.  The
compiler's header files don't include any variables.  That's why they compile
just fine.  Your's shouldn't either, but if you must, do something like this...

----file.c----
#define _FILE
#include <file.h>
int var;
/* do more stuff */
---end file.c---

----file.h----
#ifndef _FILE
extern int var;
#endif
---end file.h---

---file2.c----
#include <file.h>
/* you can now use "var" */
---end file2.c---

Hope this makes some sense...  I also could have sworn you had to do this
with typedefs, but I just tried something and it looks like maybe not.  I
dunno.  You'll have to try it yourself.

Frank Swarbrick (and his cat)           swarbric at tramp.Colorado.EDU
...!{ncar|nbires}!boulder!tramp!swarbric
"We've seen each other's hands.  What else is there?"



More information about the Comp.lang.c mailing list