lundi 28 novembre 2016

undefined reference to... terminal error, doesn't excise in eclipse

i have this code attached. when I compile and run it with eclipse, it has no problems. but in terminal, with my makeFile (attached) it gives me this error:

bin/FigureCard.o: In function `FigureCard::FigureCard(Shape const&, Figure const&)':
/home/shaike131/workspace/check/src/FigureCard.cpp:16: undefined reference to `Card::Card(Shape)'

bin/FigureCard.o: In function `FigureCard::FigureCard(FigureCard&)':
/home/shaike131/workspace/check/src/FigureCard.cpp:18: undefined reference to `Card::getShape2()'

/home/shaike131/workspace/check/src/FigureCard.cpp:18: undefined reference to `Card::Card(Shape)'

bin/FigureCard.o: In function `FigureCard::operator=(FigureCard&)':
/home/shaike131/workspace/check/src/FigureCard.cpp:22: undefined reference to `Card::getShape2()'

/home/shaike131/workspace/check/src/FigureCard.cpp:22: undefined reference to `Card::setShape(Shape)'

bin/FigureCard.o: In function `FigureCard::getShape()':
/home/shaike131/workspace/check/src/FigureCard.cpp:43: undefined reference to `Card::getShape2()'

bin/FigureCard.o: In function `FigureCard::comperator(Card*)':
/home/shaike131/workspace/check/src/FigureCard.cpp:71: undefined reference to `typeinfo for Card'

bin/FigureCard.o: In function `FigureCard::~FigureCard()':
/home/shaike131/workspace/check/src/../include/FigureCard.h:12: undefined reference to `Card::~Card()'

bin/FigureCard.o:(.rodata._ZTI10FigureCard[_ZTI10FigureCard]+0x10): undefined reference to `typeinfo for Card'
bin/NumericCard.o: In function `NumericCard::NumericCard(Shape const&, int const&)':
/home/shaike131/workspace/check/src/NumericCard.cpp:18: undefined reference to `Card::Card(Shape)'

bin/NumericCard.o: In function `NumericCard::NumericCard(NumericCard&)':
/home/shaike131/workspace/check/src/NumericCard.cpp:19: undefined reference to `Card::getShape2()'

/home/shaike131/workspace/check/src/NumericCard.cpp:19: undefined reference to `Card::Card(Shape)'

bin/NumericCard.o: In function `NumericCard::operator=(NumericCard&)':
/home/shaike131/workspace/check/src/NumericCard.cpp:24: undefined reference to `Card::getShape2()'

/home/shaike131/workspace/check/src/NumericCard.cpp:24: undefined reference to `Card::setShape(Shape)'

bin/NumericCard.o: In function `NumericCard::getShape()':
/home/shaike131/workspace/check/src/NumericCard.cpp:32: undefined reference to `Card::getShape2()'

bin/NumericCard.o: In function `NumericCard::comperator(Card*)':
/home/shaike131/workspace/check/src/NumericCard.cpp:65: undefined reference to `typeinfo for Card'

bin/NumericCard.o: In function `NumericCard::~NumericCard()':
/home/shaike131/workspace/check/src/../include/NumericCard.h:16: undefined reference to `Card::~Card()'

bin/NumericCard.o:(.rodata._ZTI11NumericCard[_ZTI11NumericCard]+0x10): undefined reference to `typeinfo for Card'

bin/Hand.o: In function `Hand::addCard(Card&)':

thanks. Shai

FigureCard class:

#include "../include/Card.h"
#include "../include/FigureCard.h"
#include <iostream>
#include <string>
using namespace std;
#include <sstream>
#include <memory>


FigureCard :: FigureCard(const Shape &shape,const Figure &figure):Card(shape),figure(figure){}

FigureCard :: FigureCard(FigureCard& other):Card(other.getShape2()), figure(other.figure){}
FigureCard& FigureCard:: operator= (FigureCard& other){

    if(this!=&other){
        this->setShape(other.getShape2());
        figure=other.figure;
    }
    return *this;
}

char FigureCard:: getFigure(){
    char s;
    switch(figure)
    {
        case Jack: s='J';break;
        case Queen: s='Q';break;
        case King : s='K';break;
        case Ace :  s='A';break;
    }

return s;
}

char FigureCard:: getShape(){
    char s;
    switch(this->getShape2())
    {
    case Club: s='C';break;
    case Diamond: s='D';break;
    case Heart : s='H';break;
    case Spade :  s='S';break;
    }

return s;
}


Figure FigureCard::getFigure2(){
    return this->figure;
}


string FigureCard:: toString()
    {
    string s(1,this->getFigure());
        s=s+this->getShape();
    return s;
    }

    int FigureCard:: comperator(Card* other){
    int ans=0;
    if (this->getType().size()==(other->getType().size())){  //if it's both FigureCard
        char figure1=this->getFigure();
        FigureCard*    fg = dynamic_cast<FigureCard*>(other);
        char figure2=fg->getFigure();

        if(figure1=='A'){
            if(figure2!='A')
                ans=1;//a is A and b is lower
        }
        else if(figure2=='A')
            ans=-1;//b is A and a is lower
        else if(figure1=='K'){
            if(figure2!='K')
                ans=1;//a is K and b is lower
        }
        else if(figure2=='K')
            ans=-1;//b is K and a is lower
        else if(figure1=='Q'){
            if(figure2!='Q')
                ans=1;//a is Q and b is lower
        }
        else if(figure2=='Q')
            ans=-1;//b is Q and a is lower


        if(ans==0){//the figures of first and second are the same
            char shape1=this->getShape();
            char shape2=other->getShape();
            if(shape1>shape2)
                ans=1;
            else if(shape1<shape2)
                ans=-1;

        }
    }

    else
        ans=1; //first card is FigureCard card and second card is NumericCard
    return ans;
    }

string FigureCard:: getType(){
    return "FigureCard";
}

NumericCard.cpp

    /*
 * NumericCard.cpp
 *
 *  Created on: Nov 28, 2016
 *      Author: shaike131
 */


#include "../include/Card.h"
#include <iostream>
#include <string>
using namespace std;
#include <sstream>
#include <memory>
#include "../include/NumericCard.h"


NumericCard :: NumericCard(const Shape &shape,const int &number):Card(shape),number(number){}
NumericCard :: NumericCard(NumericCard& other):Card(other.getShape2()), number(other.number){}
NumericCard& NumericCard:: operator= (NumericCard& other){

    if(this!=&other){
        this->number=other.number;
        this->setShape(other.getShape2());

    }
    return *this;
}

char NumericCard:: getShape(){
    char s;
    switch(this->getShape2())
    {
    case Club: s='C';break;
    case Diamond: s='D';break;
    case Heart : s='H';break;
    case Spade :  s='S';break;
    }

return s;
}



string  NumberToString ( int Number )
  {
     ostringstream ss;
     ss << Number;
     return ss.str();
  }
string NumericCard:: toString()
    {
    string s = NumberToString(number);

    s=s+this->getShape();

    return s;
    }


int NumericCard:: comperator(Card* other){
    int ans=0;
    if(this->getType().size()==other->getType().size()){  //if it's both numbers
        int num1=this->getNumber();
        NumericCard*    num = dynamic_cast<NumericCard*>(other);
        int num2=num->getNumber();
        if(num1>num2)
            ans=1;
        else if(num1<num2)
            ans=-1;
        else{
            char shape1=this->getShape();
            char shape2=other->getShape();
            if(shape1>shape2)
                ans=1;
            else if(shape1<shape2)
                ans=-1;
        }
    }
    else // if first card is NumericCard and second card is FigureCard
        ans=-1;
    return ans;
    }


string NumericCard:: getType(){
    return "NumericCard";
}
int NumericCard:: getNumber(){
    return this->number;
}

Card:

#include "../include/Card.h"
#include <iostream>
#include <string>
using namespace std;
#include <sstream>
#include <memory>


Card::Card(Shape Pshape):shape(Pshape){}
Card::Card(){}

Card::~Card() {
}

Shape Card::getShape2(){
    return this->shape;
}


void Card::setShape(Shape shape){
    this->shape=shape;
}

makeFile:

   # All Targets
all: check

# Tool invocations
# Executable "check" depends on the files CyberDNS.o,CyberExpert.o,CyberPC.o,CyberWorm.o,Cyber.o.

check: bin/Card.o bin/FigureCard.o bin/NumericCard.o bin/Deck.o bin/Player.o bin/link.o bin/linkedList.o bin/Game.o bin/Hand.o bin/check.o
    g++ -o bin/Card.o  bin/FigureCard.o bin/NumericCard.o bin/Deck.o bin/Player.o bin/link.o bin/linkedList.o bin/Game.o bin/Hand.o bin/check.o
# Depends on the source and header files

bin/Card.o: src/Card.cpp
    g++ -g -Wall -c -Linclude -o bin/Card.o src/Card.cpp
# Depends on the source and header files

bin/FigureCard.o: src/FigureCard.cpp
    g++ -g -Wall -c -Linclude -o bin/FigureCard.o src/FigureCard.cpp
# Depends on the source and header files

bin/NumericCard.o: src/NumericCard.cpp
    g++ -g -Wall -c -Linclude -o bin/NumericCard.o src/NumericCard.cpp
# Depends on the source and header files


bin/Deck.o: src/Deck.cpp
    g++ -g -Wall -c -Linclude -o bin/Deck.o src/Deck.cpp
# Depends on the source and header files

bin/Player.o: src/Player.cpp
    g++ -g -Wall -c -Linclude -o bin/Player.o src/Player.cpp
# Depends on the source and header files

bin/link.o: src/link.cpp
    g++ -g -Wall -c -Linclude -o bin/link.o src/link.cpp    
# Depends on the source and header files 

bin/linkedList.o: src/linkedList.cpp
    g++ -g -Wall -c -Linclude -o bin/linkedList.o src/linkedList.cpp

bin/Game.o: src/Game.cpp
    g++ -g -Wall -c -Linclude -o bin/Game.o src/Game.cpp

bin/Hand.o: src/Hand.cpp
    g++ -g -Wall -c -Linclude -o bin/Hand.o src/Hand.cpp

bin/check.o: src/check.cpp
    g++ -g -Wall -c -Linclude -o bin/check.o src/check.cpp

#Clean the build directory
clean: 
    $(RM) bin/*     
All:
    bin/check bin/Card.o bin/FigureCard.o bin/NumericCard.o bin/Deck.o bin/Player.o bin/link.o bin/linkedList.o bin/Game.o bin/Hand.o bin/check.o 

Aucun commentaire:

Enregistrer un commentaire