Go to Post Gotta love those free-range robots! Yum! - petek [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 14-02-2008, 12:55
Nuggets08 Nuggets08 is offline
Registered User
FRC #1737 (Project X Robotics)
Team Role: Programmer
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Excelsior Springs, MO
Posts: 11
Nuggets08 is on a distinguished road
Interesting Problems with the Compiler and Linker

Alright, I was programming and found the need to use a function pointer, I programmed it alright, my syntax was right, but the linker said it was being declared multipally. Well, I found a different way to program it, and just went on. I had this same problem trying to declare variables in header files too(I declared the function pointer in the header too).
Can anyone shed any light as to why it's complaining about this? I am really bad at figuring out linker problems, I have a mental block or something with them.
__________________
-Nuggets
Project X Robotics
Team 1737
Excelsior Springs, MO
Attending: KC-Metro Regional
Project Manager, Lead Programmer
  #2   Spotlight this post!  
Unread 14-02-2008, 13:14
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,801
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Interesting Problems with the Compiler and Linker

Never declare variables in header files (.h), otherwise, everytime you include that header file you'll be ordering the compiler to declare the variable all over again. That's why you see those "multiply defined" errors.

In the header file use:
Code:
extern char myvariable;
Then really declare the variable as a global only in one of your .c files.

There is an alternative way to declare variables in a header file that involves a conditional compile:
Code:
#ifdef DECLARE_MY_VARIABLES
    char myvariable;
#else
    extern char myvariable;
#endif
And in one (and only one) .c file
Code:
#define DECLARE_MY_VARIABLES
    #include that_header_file.h
#undef DECLARE_MY_VARIABLES
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 14-02-2008 at 14:01.
  #3   Spotlight this post!  
Unread 14-02-2008, 13:19
Nuggets08 Nuggets08 is offline
Registered User
FRC #1737 (Project X Robotics)
Team Role: Programmer
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Excelsior Springs, MO
Posts: 11
Nuggets08 is on a distinguished road
Re: Interesting Problems with the Compiler and Linker

I was going to put those variables into structs, because they all had something to do with each other, but the compiler/linker said the same thing about my defined struct.
__________________
-Nuggets
Project X Robotics
Team 1737
Excelsior Springs, MO
Attending: KC-Metro Regional
Project Manager, Lead Programmer
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
Build problems: MPLink 4.15 Linker... help? Trav-O Programming 2 12-01-2008 14:26
compiler problems sephiroth_42 Programming 4 04-02-2007 10:56
Compiler problems katkana Programming 2 03-02-2005 18:29
Free Compiler/Linker for WinXP? IMDWalrus Programming 14 05-11-2003 15:45
Interesting thing with the times Joe Ross CD Forum Support 6 14-05-2002 21:51


All times are GMT -5. The time now is 00:56.

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