Undefined Reference to 'Class::Function'

33 Views Asked by At

I'm using raylib to make a game and I've been running into problems with class methods.

objects.h

#include "raylib.h"

class Ground {

    public:
        float x;
        float y;

        float width;
        float height;

        Color groundCol;

        void Draw();

};`

objects.cpp

#include "../include/raylib.h"
#include "../include/objects.h"
#include "../include/game.h"

Game game;

Ground::Ground() {

    x = game.screenWidth / 2;
    y = game.screenHeight;
    
    width = game.screenWidth;
    height = 60;

    groundCol = GREEN;

}

Ground::Draw() {

    DrawRectanglePro({0, 0, width, height}, {x - width, y - height}, 0, groundCol);

}`

main.cpp

#include "../include/raylib.h"
#include "../include/objects.h"
#include "../include/game.h"

int main(void) {

    Game game;
    Ground ground;

    InitWindow(game.screenWidth, game.screenHeight, "freg platformer");
    SetTargetFPS(60);

    while (!WindowShouldClose()) {

        BeginDrawing();

            ground.Draw();

            ClearBackground(BLACK);

        EndDrawing();

    }

    return 0;

}`

Makefile

`default:
    g++ ./src/main.cpp -o frog.exe -O1 -Wall -std=c99 -Wno-missing-braces -L ./lib/ -lraylib -lopengl32 -lgdi32 -lwinmm`

I don't know what's wrong with my code but it throws the error:

g++ ./src/main.cpp -o .exe -O1 -Wall -std=c99 -Wno-missing-braces -L ./lib/ -lraylib -lopengl32 -lgdi32 -lwinmm
cc1plus.exe: warning: command-line option '-std=c99' is valid for C/ObjC but not for C++
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\*****\AppData\Local\Temp\ccQCl3NN.o:main.cpp:(.text+0x3a): undefined reference to `Ground::Draw()'
collect2.exe: error: ld returned 1 exit status
mingw32-make: *** [Makefile:2: default] Error 1
0

There are 0 best solutions below