You are here:

C/Global variables

Advertisement


Question
Hi!

I would like to know how can I declare a global variable in a header file. I have a project which includes 2 files (main.c and aux.c) and a common header file (define.h) that looks like this:

#ifndef _VAR
#define _VAR

/* global variables */

int number1, number2;

#endif

but when I try to make and exe file the linker shows me an error:

number1 defined in module main.c is duplicated in module aux.c

and it's the same with number2,

so, how can I solve this? I need this global variables.

I work with turboc++ 1

Thanks in advance.  

Answer
Dear Mr Updt

 Here i didn't find any problem with this header file , But i want the code for main.c and aux.c , make sure your project should have only one main module , and other header files and associated definition's will be linked further with that main module !
If you give me the code , hope it will be easy for me to spot the error

Thanks and regards
Prince M. Premnath

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Prince M. Premnath

Expertise


I'm sure that I can solve any doubts in Turbo C ,Graphics Programing ,Mouse, Hardware Programming ,File System ,Interrupts, BIOS handling , TSR Programming , General Concepts in C Language, handling inline Assembly statements

Experience

Research over 6+ Years

Organizations
CG-VAK Softwares and Exports Limited

Education/Credentials
Masters in Computer Applications

©2012 About.com, a part of The New York Times Company. All rights reserved.