undefined reference avec mingw
Bonjour,
J'ai un petit problême de compilation:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| Project : OpenGL Application
Compiler : MinGW (called directly)
Directory : F:\Programmation\Olala project\
--------------------------------------------------------------------------------
Switching to target: default
Linking executable: OlalaProject.exe
.objs\important.o:important.cpp:(.text+0x1a3): undefined reference to `actualisation::instance'
.objs\important.o:important.cpp:(.text+0x20a): undefined reference to `actualisation::instance'
.objs\important.o:important.cpp:(.text+0x2c9): undefined reference to `actualisation::instance'
.objs\important.o:important.cpp:(.text+0x330): undefined reference to `actualisation::instance'
.objs\important.o:important.cpp:(.text+0x335): undefined reference to `actualisation::instance'
.objs\important.o:important.cpp:(.text+0x35a): more undefined references to `actualisation::instance' follow
.objs\important.o:important.cpp:(.text+0x40b): undefined reference to `ecran::instance'
.objs\important.o:important.cpp:(.text+0x480): undefined reference to `ecran::instance'
.objs\important.o:important.cpp:(.text+0x4c8): undefined reference to `ecran::instance'
.objs\important.o:important.cpp:(.text+0x4d6): undefined reference to `ecran::instance'
.objs\important.o:important.cpp:(.text+0x4de): undefined reference to `ecran::instance'
.objs\important.o:important.cpp:(.text+0x503): more undefined references to `ecran::instance' follow
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 1 seconds)
0 errors, 0 warnings |
Bref c'est très joyeux. Voici le code qui va avec, d'abord important.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 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 64 65 66 67 68 69 70 71 72 73
| #ifndef IMPORTANT
#define IMPORTANT
#include <iostream>
#include <string>
#include <time.h>
#include <windows.h>
#include <GL/glut.h>
#define MENU 0
#define JEU 1
#define SON 0
#define RESEAU 1
class dessin
{
};
class actualisation //singleton
{
public:
void lancer();
static void creer();
void setRefresh_ms(int x);
int getRefresh_ms();
void setRefresh_rate(int x);
int getRefresh_rate();
static actualisation* getInstance();
static void deleteInstance();
protected:
actualisation();
~actualisation();
private:
int refresh_ms;
int refresh_rate;
static actualisation* instance;
};
//actualisation* actualisation::instance = NULL;
class ecran //singleton
{
public:
void actualiser();
static void creer(int x, int y);
void setLargeurHauteur(int x, int y);
int getLargeur();
int getHauteur();
static ecran* getInstance();
void deleteInstance();
protected:
ecran();
ecran(long x, long y);
~ecran();
private:
static ecran* instance;
int largeur;
int hauteur;
};
//ecran* ecran::instance = NULL;
void setLargeurHauteur(int x, int y);
void lancer_actualisation(); |
Puis important.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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
| #include "important.h"
void actualisation::lancer(void){}
void actualisation::creer(void)
{
if(instance == NULL)
{
instance = new actualisation;
}
}
void actualisation::setRefresh_ms(int x)
{
refresh_ms = x;
refresh_rate = 1000/refresh_ms;
}
int actualisation::getRefresh_ms(void)
{
return refresh_ms;
}
void actualisation::setRefresh_rate(int x)
{
refresh_rate = x;
refresh_ms = 1000/refresh_rate;
}
int actualisation::getRefresh_rate(void)
{
return refresh_rate;
}
actualisation* actualisation::getInstance(void)
{
if(instance == NULL)
{
instance = new actualisation();
}
return instance;
}
void actualisation::deleteInstance(void)
{
if(instance != NULL)
{
delete instance;
instance = NULL;
}
}
actualisation::actualisation(void)
{
refresh_ms = 20;
refresh_rate = 50;
}
actualisation::~actualisation(void){}
void ecran::actualiser(void)
{
}
void ecran::creer(int x, int y)
{
if(instance == NULL)
{
instance = new ecran(x,y);
}
}
void ecran::setLargeurHauteur(int x, int y)
{
largeur = x;
hauteur = y;
}
int ecran::getLargeur()
{
return largeur;
}
int ecran::getHauteur()
{
return hauteur;
}
ecran* ecran::getInstance()
{
return instance;
}
void ecran::deleteInstance()
{
if(instance != NULL)
{
delete instance;
instance = NULL;
}
}
ecran::ecran(){}
ecran::ecran(long x, long y): largeur(x), hauteur(y){}
ecran::~ecran(){}
void setLargeurHauteur(int x, int y)
{
static ecran* instance = ecran::getInstance();
instance->setLargeurHauteur(x,y);
}
void lancer_actualisation(void)
{
static actualisation* pointeur = actualisation::getInstance();
pointeur->lancer();
} |
J'utilise pour compiler MinGW (dernière version ou presque) et Code::Blocks (pareil) pour écrire le code.
Pour répondre rapidement au critiques, oui je suis un boulet mais je sais lire la doc! Juste que je sais pas la comprendre:
http://www.mingw.org/MinGWiki/index....inedReferences
Je ne sais même pas si ça traite bien de mon problême... Pour ce qui concerne le code, ce sont des classes (pas finies d'ailleurs, certaines fonctions sont encore vides également) Singleton (du moins j'ai essayer de les faire comme ça). D'ailleurs justement le problême vient de ces pointeurs pour stocker l'instance (pointer serait plus correct mais bon). Pour info vite fait, ce code a pour but d'être lancé par GLUT automatiquement (callback) qui ne veut pas de fonctions dans une classe en argument et donc j'ai fait des fonctions qui ne font que rappeller les bonnes fonctions dans les classes.
Merci d'avance si vous savez ce que je dois faire (ou plutôt ne pas faire pour éviter des erreurs comme là).