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()'”

Motor.cpp (909 Bytes)
Motor.h (473 Bytes)


Motor.cpp (909 Bytes)
Motor.h (473 Bytes)

You’re including “RoboDefs.h” twice, once in each file.

Try just including it once, or use code like this:


#ifndef RANDOM_VALUE_YOU_WONT_USE
#define RANDOM_VALUE_YOU_WONT_USE
...
#endif

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 :slight_smile: - 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)

RoboDefs is shielded like you posted

#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

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.

Heres the whole project, I changed a few little things to no avail.

Project.zip (160 KB)


Project.zip (160 KB)

I can’t find anything wrong with that…but then I don’t have windriver with me either…
Anyone else get further on this?

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.

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

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?