Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   multiple definition Problem (http://www.chiefdelphi.com/forums/showthread.php?t=72978)

Mr.Macdonald 26-01-2009 17:54

multiple definition Problem
 
2 Attachment(s)
I keep getting this error when ever I try to compile the attached code
"multiple definition of `global constructors keyed to FRC_userClassFactory()'"

demosthenes2k8 26-01-2009 18:33

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


Ryan O 26-01-2009 18:43

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)

Mr.Macdonald 26-01-2009 18:46

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

demosthenes2k8 26-01-2009 19:14

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.

Mr.Macdonald 26-01-2009 19:25

Re: multiple definition Problem
 
1 Attachment(s)
Heres the whole project, I changed a few little things to no avail.

demosthenes2k8 26-01-2009 19:39

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?

mtndurbin 26-01-2009 21:06

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.

Mr.Macdonald 27-01-2009 10:33

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

Mr.Macdonald 27-01-2009 19:45

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?


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

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