View Single Post
  #3   Spotlight this post!  
Unread 02-02-2006, 10:51
Smithvillefirst Smithvillefirst is offline
Anthony Peck
FRC #1806 (Smithville First)
Team Role: Programmer
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Smithville
Posts: 9
Smithvillefirst is an unknown quantity at this point
Re: Using vars across multiple .c files

I've tried this, but it won't work. In a file globals.h, I have the following:
int myvar;

Then, in user_routines.c I have:
#include "globals.h"
extern int myvar;

I do the same thing in tracking.c, with the include and extern declaration but I get the following linker error when I try to compile:
symbol 'myvar' has multiple definitions

I access the variable inside the default_routine function, and in another function in the tracking.c file. I've tried declaring it both inside the functions, and at the top of the .c file outside of any function, but below my preprocessor directives. Nothing seems to work. Everything look fine, but what am I doing wrong? Thanks for any ideas you guys might have.

Quote:
Originally Posted by Abwehr
define the var as:

extern mytype myvar;

in each file accessing it, except one.

Then, in ONLY ONE file (the only without an extern declaration), declare the variable normally:

mytype myvar;

See http://www.crasseux.com/books/ctutor...variables.html
__________________
Anthony Peck
Integration Manager
Team 1806