Probleme Makefile avec Objet en C++ (référence indéfinie vers )
Bon alors voila, j'ai un petit probleme de C++ mais je pense que cela vient du fait que je ne sais pas faire un Makefile ... (Mauvais linkage)
Voici mon code C++
main.cpp :
Code:
1 2 3 4 5 6 7 8 9
|
...
#include "MptMatrix.hpp"
...
main() {
...
MptMatrix<uint32> meanMx(height,width);
...
} |
Voici tout le code de MptMatrix.hpp
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
|
#ifndef MptMATRIX_H
#define MptMATRIX_H
#include <c4v.h>
template <class T>
class MptMatrix {
public:
T _pdata[];
// Default Constructor
MptMatrix(void);
// Constructor by Copy
MptMatrix(const MptMatrix& initMx);
// Constructor
MptMatrix(int r, int c, bool scanHori=true);
// Destructor
~MptMatrix();
// Get function
inline int getRows();
inline int getCols();
inline bool scanHorizontal();
void create(int r, int c, bool scanHori=true);
void loadImages(IplImage * img);
private:
// T _pdata[];
int _rows, _cols;
bool _scanHori;
};
template <class T>
inline int MptMatrix<T>::getRows() { return _rows; }
template <class T>
inline int MptMatrix<T>::getCols() { return _cols; }
template <class T>
inline bool MptMatrix<T>::scanHorizontal() { return _scanHori; }
#endif |
Le MptMatrix.cpp est correct car ca compile bien donc je vous le file pas ... (déjà assez a lire)
Et pour finir voici le code du Makefile ou se trouve surement l'erreur
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
|
# Directories
SRCDIR = src
INCDIR = include
OBJDIR = obj
# Tools
CC = gcc
CXX = g++
RM = rm -rf
CP = cp
# Flags
CFLAGS = -I$(INCDIR) `pkg-config opencv --cflags`
CXXFLAGS = -I$(INCDIR) `pkg-config opencv --cflags`
LDFLAGS = `pkg-config opencv --libs`
DEBUGOPT = -g -D_DEBUG
RELEASEOPT = -O3 -DNDEBUG
EXEC=trackpatch
objects = main \
MptMatrix \
MptLayIIM \
matching_square \
all: $(EXEC)
## Linkage
$(EXEC): $(foreach o,$(objects),$(OBJDIR)/$(o).o)
@$(CC) -o $@ $^ $(LDFLAGS)
# --------------------------
# Generation of all objects:
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
$(CXX) $(INCLUDE) $(CXXFLAGS) $(DEBUGOPT) -c $< -o $@
$(OBJDIR)/%.o: $(SRCDIR)/%.c
$(CC) $(INCLUDE) $(CFLAGS) $(DEBUGOPT) -c $< -o $@
# Nettoyage des objets
clean:
$(RM) $(OBJDIR)/*.o
# Nettoyage objets plus executable
mrproper:
clean
$(RM) $(EXEC) |
Le but etant de compiler tous les .cpp choisit dans le repertoire src/ avec leur .hpp
de pouvoir mettre les includes generaux dans le repertoire include/
Quand je parle de .cpp choisit je veux dire que le Makefile doit selectionner dans object les noms des fichiers a compiler...
objects = main \
MptMatrix \
MptLayIIM \
matching_square \
Pour finir l'execution finale du make se deroule ainsi
Code:
1 2 3 4 5 6 7 8 9 10 11
|
neub@hpdv1000:~/projetDS/openCV$ make
g++ -Iinclude `pkg-config opencv --cflags` -g -D_DEBUG -c src/main.cpp -o obj/main.o
g++ -Iinclude `pkg-config opencv --cflags` -g -D_DEBUG -c src/MptMatrix.cpp -o obj/MptMatrix.o
g++ -Iinclude `pkg-config opencv --cflags` -g -D_DEBUG -c src/MptLayIIM.cpp -o obj/MptLayIIM.o
g++ -Iinclude `pkg-config opencv --cflags` -g -D_DEBUG -c src/matching_square.cpp -o obj/matching_square.o
obj/main.o : Dans la fonction "imageProcess(char const*)":src/main.cpp:57: référence indéfinie vers « MptMatrix<unsigned int>::MptMatrix(int, int, bool)»
:src/main.cpp:71: référence indéfinie vers « MptMatrix<unsigned int>::~MptMatrix()»
:src/main.cpp:71: référence indéfinie vers « MptMatrix<unsigned int>::~MptMatrix()»
collect2: ld a retourné 1 code d'état d'exécution
make: *** [trackpatch] Erreur 1 |
Merci d'avance à tous les courageux qui vont lire mon post et surtout a tous ceux qui vont me repondre ;)