views:

59

answers:

2

I got this error message:

multiple definition of `GamepadControll::GamepadControll()'

After being frustrated for hours I reduced the code to:

GamepadControll.h:

#ifndef GAMEPADCONTROLL_H_
#define GAMEPADCONTROLL_H_

#include <iostream>

class GamepadControll {
public:
    GamepadControll();
    virtual ~GamepadControll();
};

#endif /* GAMEPADCONTROLL_H_ */

GamepadControl.cpp:

#include "GamepadControll.h"

GamepadControll::GamepadControll() {
    std::cout << "Hello, I work!" << std::endl;
}

GamepadControll::~GamepadControll() {
    // TODO Auto-generated destructor stub
}

But I just get this error message!

//Edit: Main isn't defined.. Can't I run only a class without mainfiles like in java? Here is the whole eclipse Project: http:/ul.to/m37d2z

A: 

From this sample code, there seems to be no error. The error could be multiple defined constructor GamepadControll.

Please search the constructor in code base and find any multiple instances defined

GamepadControll::GamepadControll()

Other possibility: check if you have defined constructor in header file ( which does not look to be the case from the sample code though)

aJ
+2  A: 

Most mulitply-defined-symbol error situations tend to be caused by including code into two different compilation units.

Are you sure that you're not including GamepadControl.cpp into one of your other source files?

For example, with both your files and a main.cpp holding:

#include "GamepadControll.h"
int main (void) { return 0; }

I get no errors with g++ main.cpp GamepadControll.cpp. If I change that first line to:

#include "GamepadControll.cpp"

and compile with the same command, I get:

/tmp/ccbu52oq.o: In function `GamepadControll::GamepadControll()':
GamepadControll.cpp:(.text+0x0): multiple definition of
    `GamepadControll::GamepadControll()'

The only other possibility I can think of is if you're explicitly including the code file twice. Using the error-free version of main.cpp above, I still get the error when I use:

g++ main.cpp GamepadControll.cpp GamepadControll.cpp

If it's neither of those two cases, your best bet is to provide the full details of your situation. That means every source file (including the main one), the compile and link commands you're using, and the environment (e.g., gcc3 under Linux, Code::Blocks on Windows).

paxdiablo
thxI just thought I needn't something like a main file, where the class is included. Ohhh.. these JAVA influence ^^
gnol