Problem With Finding A Constructor

I'm making a small game engine and have a project in Code::Blocks for it, and a project to test it out. The thing is that my test program won't find a constructor from the engine. Here's my code:

Game Engine, Screen.hpp
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
#ifndef SCREEN_HPP_INCLUDED
#define SCREEN_HPP_INCLUDED

#include "SDL.h"

namespace myeng
{
    class Screen final //This class doesn't need to be derived from
    {
        public:

            //Constructor and destructor
            Screen(int height, int width);
            ~Screen();

            //Functions to get the width, height, and depth of the screen
            int getScreen_Width();
            int getScreen_Height();
            int getScreen_Depth();

        private:
            //Constants
            const int SCREEN_WIDTH = 0;
            const int SCREEN_HEIGHT = 0;
            const int SCREEN_DEPTH = 0;

            //Surfaces
            SDL_Surface* screen_ptr = nullptr; //Creates the main surface for the screen
    };
}

#endif // SCREEN_HPP_INCLUDED 

Screen.cpp
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
#include "Screen.hpp"

//Cosntructor and destructor
myeng::Screen::Screen(int height, int width)
{
    const_cast<int&> (SCREEN_WIDTH) = width;
    const_cast<int&> (SCREEN_HEIGHT) = height;
    const_cast<int&> (SCREEN_HEIGHT) = 32;
    screen_ptr = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_HEIGHT, SDL_SWSURFACE);
}
myeng::Screen::~Screen()
{

}

//Functions to get width, height, and depth of the screen
int myeng::Screen::getScreen_Width()
{
    return SCREEN_WIDTH;
}
int myeng::Screen::getScreen_Height()
{
    return SCREEN_HEIGHT;
}
int myeng::Screen::getScreen_Depth()
{
    return SCREEN_DEPTH;
}

Test Project, main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include "Screen.hpp"

int main ( int argc, char* argv[] )
{
    if(SDL_Init(SDL_INIT_EVERYTHING) != 0)
    {
        std::cerr << "Failed to inialize SDL. Error:  " << SDL_GetError << "\n";
        return 1;
    }

    myeng::Screen main_screen(600, 600);

    //std::cout << main_screen.getScreen_Width();

    return 0;
}

I have my engine project correctly linking to the SDL dlls and the test project linking to the engine dll and the SDL dlls. The errors are:

obj\Debug\main.o||In function `SDL_main':|
C:\Users\Main\Documents\Programs\Game_Engine_Test\main.cpp|12|undefined reference to `myeng::Screen::Screen(int, int)'|
C:\Users\Main\Documents\Programs\Game_Engine_Test\main.cpp|16|undefined reference to `myeng::Screen::~Screen()'|
||=== Build finished: 2 errors, 0 warnings ===|

Last edited on
You need to compile the engine (either by adding the source files to the test project or separately compiling it into an object file and linking to that in the test project). If you only include the header files in the test project, the compiler will only see the function declarations but not the definitions.
I compiled the engine into a .dll and the linked the test program to that.
I added the SDL_Game_Engine.dll to my link libraries for the test program, but now it tells me:

ld.exe||cannot find -lSDL_Game_Engine.dll|
I'm pretty sure you can't link to a DLL at compile time, you may also need to compile it into an
.a
file and link to that. Type the entire filename into the link libraries window. It should give you the option of opening a file dialogue.
I put in the full path in the link libraries and it will compile and run, but it won't open any window.
Last edited on
That's an SDL problem. I don't know much of anything about SDL so I won't be of much help to you there.
I figured it out. I was accidentally setting the bpp to the height of the screen. Thanks for your help.
Topic archived. No new replies allowed.