Below is my code. The problem I am facing is it says undefined reference to the constructor of Ball(). I googled about it and some says it's a linking error. So I am also attaching the Make file that I am using to compile.

World.h
    #ifndef WORLD_H
    #define WORLD_H

    #include "Ball.h"
    #include "Camera.h"
    #include "Stick.h"

     class World
     {

     public:
        Ball ball[15];
        Ball qBall;
        Camera camera;
        World();
        void update();
        void render();
     };

    #endif

world.cpp

    #include "World.h"

    World::World(){
        // set all initial declaration
     }
     //**************************************************************
     void World::update(){
        for (int i = 0; i < 15; ++i)
        {
            ball[i].update();
        }
     }

     //**************************************************************
     void World::render(){

     }

Here is the error I am getting:

    ./libWorld.a(World.o): In function `World::World()':
    World.cpp:(.text+0x21): undefined reference to `Ball::Ball()'
    World.cpp:(.text+0x46): undefined reference to `Ball::Ball()'
    World.cpp:(.text+0x58): undefined reference to `Camera::Camera()'
    ./libWorld.a(World.o): In function `World::update()':
    World.cpp:(.text+0x97): undefined reference to `Ball::update()'
    collect2: ld returned 1 exit status
    make: *** [a.out] Error 1

The make file that I am using if it is a linking error:

    a.out: readobj.cpp libBall.a libWorld.a libCamera.a libStick.a
        g++ -Wall readobj.cpp -L. -lBall -lWorld -lCamera -lStick -lglut -lGLU

    libWorld.a: World.o
        ar -rcs libWorld.a World.o
    World.o: World.cpp World.h libCamera.a libStick.a libBall.a
        g++ -Wall -c World.cpp -L. -lCamera -lStick -lBall


    libCamera.a: Camera.o
        ar -rcs libCamera.a Camera.o
    Camera.o: Camera.cpp Camera.h Game.h
        g++ -Wall -c Camera.cpp


    libStick.a: Stick.o
        ar -rcs libStick.a Stick.o
    Stick.o: Stick.cpp Stick.h Game.h
        g++ -Wall -c Stick.cpp


    libBall.a: Ball.o
        ar -rcs libBall.a Ball.o
    Ball.o: Ball.cpp Ball.h Game.h
        g++ -Wall -c Ball.cpp
有帮助吗?

解决方案

The problem was with the linking library order, Its fixed now.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top