2017-07-25 2 views
0

Je rencontre des difficultés pour compiler mon projet Je suis en train de coder les fichiers wordbench2.h, wordbench2.cpp, makefile.wb2, oaa_bst.h pour le fichier principal que j'ai reçu (main_wb2.cpp) Je me demandais si quelqu'un voit quelque chose de mal dans mon makefilemakefile erreur de référence indéfinie

LIB  = /home/courses/cop4530p/LIB 
CPP  = $(LIB)/cpp 
TCPP = $(LIB)/tcpp 
PROJ = . 
INCPATH = -I$(PROJ)-I$(CPP)-I$(TCPP) 
CC  = g++ -std=c++11 -Wall -Wextra -I. -I$(CPP) 

#target: 
all: wb2.x foaa.x moaa.x 
#foaa+.x 

main_wb2.o: wordbench2.h main_wb2.cpp 
     $(CC) -c main_wb2.cpp 

foaa.o: wordbench2.h foaa.cpp 
     $(CC) -c foaa.cpp 

moaa.o: wordbench2.h moaa.cpp 
     $(CC) -c moaa.cpp 

wordbench2.o: wordbench2.h wordbench2.cpp wordify.cpp 
     $(CC) -c wordbench2.cpp 

xstring.o: $(CPP)/xstring.h $(CPP)/xstring.cpp 
     $(CC) $(INCPATH) -c $(CPP)/xstring.cpp 

wb2.x: main_wb2.o wordbench2.o xstring.o 
     $(CC) -o wb2.x main_wb2.o 

foaa.x: foaa.o wordbench2.o xstring.o 
     $(CC) -o foaa.x foaa.o 

moaa.x: moaa.o wordbench2.o xstring.o 
     $(CC) -o moaa.x moaa.o 

erreur

g++ -std=c++11 -Wall -Wextra -I. -I/home/courses/cop4530p/LIB/cpp -o wb2.x main_wb2.o     
main_wb2.o: In function `main': 
main_wb2.cpp:(.text+0xfd): undefined reference to `WordBench::WordBench()' 
main_wb2.cpp:(.text+0x109): undefined reference to `fsu::String::String()' 
main_wb2.cpp:(.text+0x115): undefined reference to `fsu::String::String()' 
main_wb2.cpp:(.text+0x1ad): undefined reference to `fsu::operator>>(std::istream&, fsu::String&)' 
main_wb2.cpp:(.text+0x1c4): undefined reference to `fsu::operator<<(std::ostream&, fsu::String const&)' 
main_wb2.cpp:(.text+0x1f1): undefined reference to `fsu::operator<<(std::ostream&, fsu::String const&)' 
main_wb2.cpp:(.text+0x21e): undefined reference to `fsu::operator>>(std::istream&, fsu::String&)' 
main_wb2.cpp:(.text+0x235): undefined reference to `fsu::operator<<(std::ostream&, fsu::String const&)' 
main_wb2.cpp:(.text+0x25d): undefined reference to `WordBench::ReadText(fsu::String const&, bool)' 
main_wb2.cpp:(.text+0x28f): undefined reference to `fsu::operator>>(std::istream&, fsu::String&)' 
main_wb2.cpp:(.text+0x2a6): undefined reference to `fsu::operator<<(std::ostream&, fsu::String const&)' 
main_wb2.cpp:(.text+0x2d3): undefined reference to `fsu::operator<<(std::ostream&, fsu::String const&)' 
main_wb2.cpp:(.text+0x300): undefined reference to `fsu::operator>>(std::istream&, fsu::String&)' 
main_wb2.cpp:(.text+0x317): undefined reference to `fsu::operator<<(std::ostream&, fsu::String const&)' 
main_wb2.cpp:(.text+0x33f): undefined reference to `WordBench::ReadText(fsu::String const&, bool)' 
main_wb2.cpp:(.text+0x371): undefined reference to `fsu::operator>>(std::istream&, fsu::String&)' 
main_wb2.cpp:(.text+0x388): undefined reference to `fsu::operator<<(std::ostream&, fsu::String const&)' 
main_wb2.cpp:(.text+0x3b5): undefined reference to `fsu::operator<<(std::ostream&, fsu::String const&)' 
main_wb2.cpp:(.text+0x3e2): undefined reference to `fsu::operator>>(std::istream&, fsu::String&)' 
main_wb2.cpp:(.text+0x3f9): undefined reference to `fsu::operator<<(std::ostream&, fsu::String const&)' 
main_wb2.cpp:(.text+0x42f): undefined reference to `WordBench::WriteReport(fsu::String const&, unsigned short, unsigned short, std::_Ios_Fmtflags, std::_Ios_Fmtflags) const' 
main_wb2.cpp:(.text+0x44d): undefined reference to `fsu::String::operator=(fsu::String const&)' 
main_wb2.cpp:(.text+0x45e): undefined reference to `fsu::String::Size() const' 
main_wb2.cpp:(.text+0x488): undefined reference to `fsu::String::Cstr() const' 
main_wb2.cpp:(.text+0x4d9): undefined reference to `fsu::operator<<(std::ostream&, fsu::String const&)' 
main_wb2.cpp:(.text+0x572): undefined reference to `WordBench::ClearData()' 
main_wb2.cpp:(.text+0x595): undefined reference to `WordBench::ShowSummary() const' 
main_wb2.cpp:(.text+0x67a): undefined reference to `fsu::String::~String()' 
main_wb2.cpp:(.text+0x686): undefined reference to `fsu::String::~String()' 
main_wb2.cpp:(.text+0x695): undefined reference to `WordBench::~WordBench()' 
main_wb2.cpp:(.text+0x6cb): undefined reference to `fsu::String::~String()' 
main_wb2.cpp:(.text+0x6dc): undefined reference to `fsu::String::~String()' 
main_wb2.cpp:(.text+0x6f0): undefined reference to `WordBench::~WordBench()' 
collect2: error: ld returned 1 exit status 
make: *** [wb2.x] Error 1 

Répondre

0

dans cette règle:

wb2.x: main_wb2.o wordbench2.o xstring.o 
     $(CC) -o wb2.x main_wb2.o 

vous liste wordbench2.o et xstring.o dans votre liste des prérequis, mais vous ne les avez pas mis sur la ligne de compilation. Pourquoi réécrivez-vous les mêmes choses encore et encore? Cela conduit juste à des erreurs stupides comme ça. Utilisez automatic variables pour éviter de retaper et se tromper:

wb2.x: main_wb2.o wordbench2.o xstring.o 
     $(CC) -o [email protected] $^ 

Même chose pour vos autres règles de liaison.

+0

Et pour vos règles de compilation, mettez le '* .cpp' comme premier prérequis et utilisez la variable automatique' $ <'(première condition préalable) dans votre recette. –