Go to Post On these forums, there are so many people that we see working all of the time to try to help teams out, and just overall good people. To everyone who does that, thanks. - miketwalker [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 17-05-2004, 14:41
Max Lobovsky's Avatar
Max Lobovsky Max Lobovsky is offline
Fold em oval!
FRC #1257 (Parallel Universe)
Team Role: College Student
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Scotch Plains, NJ
Posts: 1,026
Max Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant future
Send a message via AIM to Max Lobovsky
Linker Error

I get the following error whenever i try to compile FRCcode with any variables declared in user_routines.h (in this case, "int bob;"):

MPLINK 3.40, Linker
Copyright (c) 2003 Microchip Technology Inc.
Error - symbol 'bob' has multiple definitions.
Errors : 1


I'm positive i don't have multiple definitions. It appears that user_routines.h is being included several times. i understand repeated #defines would be protected by the

Code:
#ifndef __user_program_h_
#define __user_program_h_
....
#endif

but how do i protect real code (not #define's) from being repeatedly inserted?

The program compiles fine with the variables in user_routines.c, i'd just prefer these global constants to be in the header for convenience.
__________________
Learn, edit, inspire: The FIRSTwiki.
Team 1257


2005 NYC Regional - 2nd seed, Xerox Creativity Award, Autodesk Visualization Award
2005 Chesapeake Regional - Engineering Inspiration Award
2004 Chesapeake Regional - Rookie Inspiration award
2004 NJ Regional - Team Spirit Award
  #2   Spotlight this post!  
Unread 17-05-2004, 15:05
Gene F's Avatar
Gene F Gene F is offline
FIRST Fanatic
AKA: Gene Falendysz
#0343 (Metal in Motion)
Team Role: Engineer
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Oconee County, SC
Posts: 218
Gene F is a splendid one to beholdGene F is a splendid one to beholdGene F is a splendid one to beholdGene F is a splendid one to beholdGene F is a splendid one to beholdGene F is a splendid one to beholdGene F is a splendid one to beholdGene F is a splendid one to behold
Send a message via AIM to Gene F
Re: Linker Error

Quote:
Originally Posted by maxlobovsky
I get the following error whenever i try to compile FRCcode with any variables declared in user_routines.h (in this case, "int bob;"):

MPLINK 3.40, Linker
Copyright (c) 2003 Microchip Technology Inc.
Error - symbol 'bob' has multiple definitions.
Errors : 1


I'm positive i don't have multiple definitions. It appears that user_routines.h is being included several times. i understand repeated #defines would be protected by the

Code:
#ifndef __user_program_h_
#define __user_program_h_
....
#endif

but how do i protect real code (not #define's) from being repeatedly inserted?

The program compiles fine with the variables in user_routines.c, i'd just prefer these global constants to be in the header for convenience.
The problem is that you are decalring bob in the header. It needs to be declared in the user_routines.c file and externed in the user_routines.h file.

So in user_routines.c it would look like:
int bob;
In user_routines.h it would be:
extern int bob;

What's happening is that each file that includes user_routines.h is creating a new copy of bob rather than just getting a reference to it.

Some compilers/linkers let you decare in the header file but in general it is not supported.
__________________
- Gene Falendysz
  #3   Spotlight this post!  
Unread 17-05-2004, 15:41
Max Lobovsky's Avatar
Max Lobovsky Max Lobovsky is offline
Fold em oval!
FRC #1257 (Parallel Universe)
Team Role: College Student
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Scotch Plains, NJ
Posts: 1,026
Max Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant future
Send a message via AIM to Max Lobovsky
Re: Linker Error

Ah, right, i forgot about using extern when its in a different file. So the extern modifier tells the compiler to ignore multiple declarations?
__________________
Learn, edit, inspire: The FIRSTwiki.
Team 1257


2005 NYC Regional - 2nd seed, Xerox Creativity Award, Autodesk Visualization Award
2005 Chesapeake Regional - Engineering Inspiration Award
2004 Chesapeake Regional - Rookie Inspiration award
2004 NJ Regional - Team Spirit Award
  #4   Spotlight this post!  
Unread 18-05-2004, 07:36
Astronouth7303's Avatar
Astronouth7303 Astronouth7303 is offline
Why did I come back?
AKA: Jamie Bliss
FRC #4967 (That ONE Team)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Grand Rapids, MI
Posts: 2,071
Astronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud ofAstronouth7303 has much to be proud of
Re: Linker Error

No, extern tells the compiler that it is declared in another file, your just using it.

char foo = 0;
...
extern char foo;
  #5   Spotlight this post!  
Unread 27-05-2004, 20:16
wun's Avatar
wun wun is offline
Registered User
AKA: David Wolever
#0865 (Warp7)
Team Role: Programmer
 
Join Date: Dec 2003
Rookie Year: 2001
Location: Toronto
Posts: 84
wun will become famous soon enough
Send a message via AIM to wun Send a message via MSN to wun
Re: Linker Error

This sounds exactly like a problem I had.
It happened to me when I was trying to define variables in the .h files
You can either use extern, or just put them in the .c files (thats what I ended up doing)
__________________
Help Microsoft stop piracy. Use Linux!

I have three gmail invitations, message me if you want one
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in Visual C++ Ashley Weed Programming 15 06-05-2004 14:53
Strange 16 bit MS-DOS subsystem error Crazy_Ed Programming 6 18-03-2004 14:31
Error message in MPLAB IDE dddriveman Programming 11 18-03-2004 06:34
strange error Anthony Kesich Programming 2 25-02-2004 18:55
EMERGENCY! EPROM FULL error?!? CHSguard72 Programming 2 05-03-2003 20:51


All times are GMT -5. The time now is 17:51.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi