Problem with SDL(blieved to be in classes)

Hi, I have been working with SDL for a little while and all of a sudden I'm encountering this problem..
obj\Debug\Application.o||In function `Application':|
C:\Users\Cody\Desktop\New Folder\test\Application.cpp|4|undefined reference to `Window::Window()'|
C:\Users\Cody\Desktop\New Folder\test\Application.cpp|4|undefined reference to `Window::Window()'|
obj\Debug\Application.o||In function `~Application':|
C:\Users\Cody\Desktop\New Folder\test\Application.cpp|12|undefined reference to `Window::~Window()'|
C:\Users\Cody\Desktop\New Folder\test\Application.cpp|12|undefined reference to `Window::~Window()'|
obj\Debug\Application.o:C:\Users\Cody\Desktop\New Folder\test\Application.cpp|21|undefined reference to `Window::Init(int, int, int, unsigned int)'|
||=== Build finished: 5 errors, 0 warnings ===|


When I click it actually shows the .cpp of Application with the functions.

heres the code ive got..

Application.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#ifndef APPLICATION_H_INCLUDED
#define APPLICATION_H_INCLUDED

#include <SDL/SDL.h>
#include "Window.h"

class Application
{
    private:
        bool m_bDone;
        Window mWindow;
    public:
        Application();
        ~Application();

        bool Init();
        void Run();
        void TakeInput(SDL_Event* pEvent);
        void Update();
        void Render();
        void Quit();
};

#endif 

Application.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "Application.h"


Application::Application()
{
    m_bDone = false;
}

Application::~Application()
{

}

bool Application::Init()
{
    if(SDL_Init(SDL_INIT_EVERYTHING) != 0)
    {
        return false;
    }

    if(mWindow.Init(640, 460, 32, SDL_SWSURFACE) != true)
    {
        return false;
    }

    return true;
}

void Application::Run()
{
    while(!m_bDone)
    {
        m_bDone = true;
    }
}

void Application::TakeInput(SDL_Event* pEvent)
{

}

void Application::Update()
{

}

void Application::Render()
{
}

void Application::Quit()
{
    SDL_Quit();
}

Window.h
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
33
34
35
36
37
38
#ifndef WINDOW_H_INCLUDED
#define WINDOW_H_INCLUDED

#include <string>

#include <SDL/SDL.h>



class Window
{
    private:
    int m_1Width;
    int m_1Height;
    int m_1BPP;
    Uint32 M_1Flags;

    SDL_Surface* mWindow;
    std::string mTitle;


    public:
    Window();
    ~Window();

    int GetWidth() const;
    int GetHeight() const;
    int GetBPP() const;
    Uint32 GetFlags() const;
    SDL_Surface* GetSurface() const;
    std::string GetTitle() const;

    void SetTitle(std::string title);
    bool Init(int width, int height, int bpp, Uint32 flags);

};

#endif 

Window.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "Window.h"

Window::Window()
{
    m_1Width = 0;
    m_1Height = 0;
    m_1BPP = 0;
    m_1Flags = 0;
    mWindow = NULL;
    mTitle = "SDL app";
}

Window::~Window()
{

}

int Window::GetWidth() const
{
    return m_1Width;
}

int Window::GetHeight() const
{
    return m_1Height;
}

int Window::GetBPP() const
{
    return m_1BPP;
}

Uint32 Window::GetFlags() const
{
    return m_1Flags;
}

SDL_Surface* Window::GetSurface() const
{
    return mWindow;
}

std::string Window::GetTitle() const
{
    return mTitle;
}

void Window::SetTitle(std::string title)
{
    mTitle = title;
    SDL_WM_SetCaption(mTitle.c_str(), NULL);

}

bool Window::Init(int width, int height, int bpp, Uint32 flags)
{
    m_1Width = width;
    m_1Height = height;
    M_1BPP = bpp;
    m_1Flags = flags;

    if(mWindow = (SDL_SetVideoMode(m_1Width, m_1Height, m_1BPP, m_1Flags)) == NULL)
    {
            return false;
    }
    return true;
}


main.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
#include "SDL/SDL.h"
#include "Application.h"
#include "Window.h"

Application* pApp;

int main(int args, char* argv[])
{
        pApp = new Application();

        if(pApp->Init() != true)
        {
            return -1;
        }

        pApp->Run();

        pApp->Quit();

        if(pApp)
        {
            delete pApp;
            pApp = NULL;
        }

        return 0;
}
For some reason it's not finding the bodies of the Window ctor,dtor, and Init function. You must not be linking to Window.cpp


make sure Window.cpp is part of your project. If you're using Code::Blocks, it has this stupid thing where when you add new files to a project, by default it doesn't link them into your builds for whatever reason (it actually really frustrated me). In this case I would remove Window.cpp from the project, then add it again -- and when you add it, be sure to check both of the Debug and Release checkboxes on the Add New Item window that pops up to make sure it gets linked.
okay.. I tried that andd... It works! I'll have to remember this incase it happens again. I prefer Code::Blocks over any other IDE still
Topic archived. No new replies allowed.