Go to Post I am alive today because I can't hold onto things. - Al Skierkiewicz [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 26-01-2009, 17:54
Mr.Macdonald Mr.Macdonald is offline
Registered User
FRC #2272
 
Join Date: Jan 2009
Location: Conejo Valley Robotics
Posts: 26
Mr.Macdonald is an unknown quantity at this point
multiple definition Problem

I keep getting this error when ever I try to compile the attached code
"multiple definition of `global constructors keyed to FRC_userClassFactory()'"
Attached Files
File Type: cpp Motor.cpp (909 Bytes, 21 views)
File Type: h Motor.h (473 Bytes, 20 views)
Reply With Quote
  #2   Spotlight this post!  
Unread 26-01-2009, 18:33
demosthenes2k8's Avatar
demosthenes2k8 demosthenes2k8 is offline
Graduated but not gone
AKA: Matt Soucy
FRC #0166 (Chop Shop 166)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2007
Location: Merrimack, NH
Posts: 589
demosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to behold
Send a message via AIM to demosthenes2k8 Send a message via Yahoo to demosthenes2k8
Re: multiple definition Problem

You're including "RoboDefs.h" twice, once in each file.

Try just including it once, or use code like this:
Code:
#ifndef RANDOM_VALUE_YOU_WONT_USE
#define RANDOM_VALUE_YOU_WONT_USE
...
#endif
Reply With Quote
  #3   Spotlight this post!  
Unread 26-01-2009, 18:43
Ryan O's Avatar
Ryan O Ryan O is offline
FRC Eclipse Plug-in Developer
no team (FRC Eclipse)
Team Role: Programmer
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Plaistow
Posts: 111
Ryan O is an unknown quantity at this point
Send a message via AIM to Ryan O
Re: multiple definition Problem

I would recommend using the second method dem. mentioned - it's a good habit to get into. Basically, it checks to see if anything called RANDOM_VALUE_YOU_WONT_USE has been defined yet, via the #ifndef line - everything between it and the #endif is skipped if the symbol after it has been defined previously. If it has not been defined, it defines it (#define) and then does whatever. It helps keep code and such from being accidentally repeated. The RANDOM_VALUE_YOU_WONT_USE should be replaced with a unique and descriptive title, such as MOTOR_CLASS_SYMBOL for your motor header. One thing to be careful of - don't repeat a title, as it skip the code if it has been defined elsewhere first - (that's what it's meant to do in this case, after all - So just name it something you know wouldn't be used again - and don't worry about it being long (you'll only be typing it twice, after all)
__________________
CRUD Name: Windows
Rookie Year: 2005
Alumni to Team: 350
Reply With Quote
  #4   Spotlight this post!  
Unread 26-01-2009, 18:46
Mr.Macdonald Mr.Macdonald is offline
Registered User
FRC #2272
 
Join Date: Jan 2009
Location: Conejo Valley Robotics
Posts: 26
Mr.Macdonald is an unknown quantity at this point
Re: multiple definition Problem

RoboDefs is shielded like you posted

Code:
#ifndef RANDOM_VALUE_YOU_WONT_USE
#define RANDOM_VALUE_YOU_WONT_USE
...Code...
#endif
I have other files importing RoboDefs.h multiple times, and it works fine.
I will post my whole project (zipped) if needed

EDIT: Show I protect my .cpp files too

Last edited by Mr.Macdonald : 26-01-2009 at 18:52.
Reply With Quote
  #5   Spotlight this post!  
Unread 26-01-2009, 19:14
demosthenes2k8's Avatar
demosthenes2k8 demosthenes2k8 is offline
Graduated but not gone
AKA: Matt Soucy
FRC #0166 (Chop Shop 166)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2007
Location: Merrimack, NH
Posts: 589
demosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to behold
Send a message via AIM to demosthenes2k8 Send a message via Yahoo to demosthenes2k8
Re: multiple definition Problem

Maybe that'll help...
What's the term for the second method again?

It's also good for writing your own libraries...If you want to replace something with your own version, just #define to make it exclude the other file, then #include your own changed copy.

Last edited by demosthenes2k8 : 26-01-2009 at 19:20.
Reply With Quote
  #6   Spotlight this post!  
Unread 26-01-2009, 19:25
Mr.Macdonald Mr.Macdonald is offline
Registered User
FRC #2272
 
Join Date: Jan 2009
Location: Conejo Valley Robotics
Posts: 26
Mr.Macdonald is an unknown quantity at this point
Re: multiple definition Problem

Heres the whole project, I changed a few little things to no avail.
Attached Files
File Type: zip Project.zip (160.3 KB, 19 views)
Reply With Quote
  #7   Spotlight this post!  
Unread 26-01-2009, 19:39
demosthenes2k8's Avatar
demosthenes2k8 demosthenes2k8 is offline
Graduated but not gone
AKA: Matt Soucy
FRC #0166 (Chop Shop 166)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2007
Location: Merrimack, NH
Posts: 589
demosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to behold
Send a message via AIM to demosthenes2k8 Send a message via Yahoo to demosthenes2k8
Re: multiple definition Problem

I can't find anything wrong with that...but then I don't have windriver with me either...
Anyone else get further on this?
Reply With Quote
  #8   Spotlight this post!  
Unread 26-01-2009, 21:06
mtndurbin mtndurbin is offline
Programming Mentor
FRC #0662 (Rocky Mountain Robotics)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2004
Location: Colorado Springs, CO
Posts: 8
mtndurbin is an unknown quantity at this point
Re: multiple definition Problem

The problem is that you have the following line in your RoboDefs.h

START_ROBOT_CLASS(Main);

This is a macro defined in RobotBase.h (for reference).

This macro should only be in your Main.cpp file, and at the bottom works.

Peter Rivera
Mentor, Team 662.
Reply With Quote
  #9   Spotlight this post!  
Unread 27-01-2009, 10:33
Mr.Macdonald Mr.Macdonald is offline
Registered User
FRC #2272
 
Join Date: Jan 2009
Location: Conejo Valley Robotics
Posts: 26
Mr.Macdonald is an unknown quantity at this point
Re: multiple definition Problem

Quote:
The problem is that you have the following line in your RoboDefs.h

START_ROBOT_CLASS(Main);

This is a macro defined in RobotBase.h (for reference).

This macro should only be in your Main.cpp file, and at the bottom works.

Peter Rivera
Mentor, Team 662.
Did you get it to compile, I can't test now but that makes sense. but why couldn't I put it at the end to the Main.h?

EDIT: But inside the macro shields
Reply With Quote
  #10   Spotlight this post!  
Unread 27-01-2009, 19:45
Mr.Macdonald Mr.Macdonald is offline
Registered User
FRC #2272
 
Join Date: Jan 2009
Location: Conejo Valley Robotics
Posts: 26
Mr.Macdonald is an unknown quantity at this point
Re: multiple definition Problem

Putting the "START_ROBOT_CLASS(Main);" in the main.cpp allowed it to compile, but now I can't get the printing to work. It seems as though my code doesn't even run.

Is there another way to write the "Main" class?
Reply With Quote
Reply


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
Definition of orthogonal.... fhobart General Forum 9 08-01-2009 12:38
[FTC]: Multiple Programs or One Program with Multiple Auto Modes kevin51292 FIRST Tech Challenge 4 02-01-2009 20:37
definition of FUNCPTR shavol Programming 6 28-12-2008 19:00
Hosting multiple sites in multiple VMs EHaskins Website Design/Showcase 6 22-12-2007 01:09
multiple definition error in MCC/Linker (possible bug?) wun Programming 5 01-04-2004 17:49


All times are GMT -5. The time now is 02:40.

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