Erreur de compilation "multiple definition of"
Bonjour,
je cherche à realiser un prgramme C++ qui réalise un screenshot toutes les x millisecondes.
j'ai récupéré le code d'un "timer", mais je n'arrive pas à compiler.
Si qqun a une idée, je suis preneur !
Merci d'avance !
Voici le code :
Screenshot.cpp
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#include <iostream>
#include "Timer.cpp"
using namespace std;
int main() {
Timer timer;
int repetitions = 0;
timer.start();
while (repetitions < 100) {
if (timer.getTime() > 500) {
cout << "Répétition n°" << repetitions << endl;
timer.reset();
repetitions ++;
}
}//Fin boucle
timer.stop();
return 0;
} |
Timer.cpp
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
#include "Timer.h"
#include <time.h>
Timer::Timer() {
resetted = true;
running = false;
beg = 0;
end = 0;
}
Timer::~Timer() {
// TODO Auto-generated destructor stub
}
void Timer::start() {
if(! running) {
if(resetted)
beg = (unsigned long) clock();
else
beg -= end - (unsigned long) clock();
running = true;
resetted = false;
}
}
void Timer::stop() {
if(running) {
end = (unsigned long) clock();
running = false;
}
}
void Timer::reset() {
bool wereRunning = running;
if(wereRunning)
stop();
resetted = true;
beg = 0;
end = 0;
if(wereRunning)
start();
}
bool Timer::isRunning() {
return running;
}
unsigned long Timer::getTime() {
if(running)
return ((unsigned long) clock() - beg) / CLOCKS_PER_SEC;
else
return end - beg;
}
bool Timer::isOver(unsigned long seconds) {
return seconds >= getTime();
} |
Timer.h
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#ifndef TIMER_H_
#define TIMER_H_
class Timer {
public:
Timer();
virtual ~Timer();
void start();
void stop();
void reset();
bool isRunning();
unsigned long getTime();
bool isOver(unsigned long seconds);
private:
bool resetted;
bool running;
unsigned long beg;
unsigned long end;
};
#endif /* TIMER_H_ */ |
Et Voici l'erreur que j'obtiens :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
**** Build of configuration Debug for project Screenshot ****
make all
Building file: ../src/Screenshot.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/Screenshot.d" -MT"src/Screenshot.d" -o"src/Screenshot.o" "../src/Screenshot.cpp"
Finished building: ../src/Screenshot.cpp
Building file: ../src/Timer.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/Timer.d" -MT"src/Timer.d" -o"src/Timer.o" "../src/Timer.cpp"
Finished building: ../src/Timer.cpp
Building target: Screenshot
Invoking: GCC C++ Linker
g++ -o"Screenshot" ./src/Screenshot.o ./src/Timer.o
./src/Timer.o: In function `Timer':
/media/data/workspaces/WorkspaceC-CPP/Screenshot/Debug/../src/Timer.cpp:11: multiple definition of `Timer::Timer()'
./src/Screenshot.o:/media/data/workspaces/WorkspaceC-CPP/Screenshot/Debug/../src/Timer.cpp:11: first defined here
./src/Timer.o: In function `Timer':
/media/data/workspaces/WorkspaceC-CPP/Screenshot/Debug/../src/Timer.cpp:11: multiple definition of `Timer::Timer()'
./src/Screenshot.o:/media/data/workspaces/WorkspaceC-CPP/Screenshot/Debug/../src/Timer.cpp:11: first defined here
./src/Timer.o: In function `~Timer':
/media/data/workspaces/WorkspaceC-CPP/Screenshot/Debug/../src/Timer.cpp:18: multiple definition of `Timer::~Timer()'
./src/Screenshot.o:/media/data/workspaces/WorkspaceC-CPP/Screenshot/Debug/../src/Timer.cpp:18: first defined here
./src/Timer.o: In function `~Timer':
/media/data/workspaces/WorkspaceC-CPP/Screenshot/Debug/../src/Timer.cpp:18: multiple definition of `Timer::~Timer()'
./src/Screenshot.o:/media/data/workspaces/WorkspaceC-CPP/Screenshot/Debug/../src/Timer.cpp:18: first defined here
./src/Timer.o: In function `~Timer':
/media/data/workspaces/WorkspaceC-CPP/Screenshot/Debug/../src/Timer.cpp:18: multiple definition of `Timer::~Timer()'
./src/Screenshot.o:/media/data/workspaces/WorkspaceC-CPP/Screenshot/Debug/../src/Timer.cpp:18: first defined here
./src/Timer.o: In function `Timer::start()':
/media/data/workspaces/WorkspaceC-CPP/Screenshot/Debug/../src/Timer.cpp:22: multiple definition of `Timer::start()'
./src/Screenshot.o:/media/data/workspaces/WorkspaceC-CPP/Screenshot/Debug/../src/Timer.cpp:22: first defined here
./src/Timer.o: In function `Timer::stop()':
/media/data/workspaces/WorkspaceC-CPP/Screenshot/Debug/../src/Timer.cpp:34: multiple definition of `Timer::stop()'
./src/Screenshot.o:/media/data/workspaces/WorkspaceC-CPP/Screenshot/Debug/../src/Timer.cpp:34: first defined here
./src/Timer.o: In function `Timer::reset()':
/media/data/workspaces/WorkspaceC-CPP/Screenshot/Debug/../src/Timer.cpp:42: multiple definition of `Timer::reset()'
./src/Screenshot.o:/media/data/workspaces/WorkspaceC-CPP/Screenshot/Debug/../src/Timer.cpp:42: first defined here
./src/Timer.o: In function `Timer::isRunning()':
/media/data/workspaces/WorkspaceC-CPP/Screenshot/Debug/../src/Timer.cpp:54: multiple definition of `Timer::isRunning()'
./src/Screenshot.o:/media/data/workspaces/WorkspaceC-CPP/Screenshot/Debug/../src/Timer.cpp:54: first defined here
./src/Timer.o: In function `Timer::getTime()':
/media/data/workspaces/WorkspaceC-CPP/Screenshot/Debug/../src/Timer.cpp:59: multiple definition of `Timer::getTime()'
./src/Screenshot.o:/media/data/workspaces/WorkspaceC-CPP/Screenshot/Debug/../src/Timer.cpp:59: first defined here
./src/Timer.o: In function `Timer::isOver(unsigned long)':
/media/data/workspaces/WorkspaceC-CPP/Screenshot/Debug/../src/Timer.cpp:67: multiple definition of `Timer::isOver(unsigned long)'
./src/Screenshot.o:/media/data/workspaces/WorkspaceC-CPP/Screenshot/Debug/../src/Timer.cpp:67: first defined here
collect2: ld returned 1 exit status
make: *** [Screenshot] Erreur 1 |