0

Ошибка:

C:\Users\486B~1\AppData\Local\Temp\ccRMYmsr.o:main.cpp:(.text+0x5d): undefined reference to `__gxx_personality_sj0'
C:\Users\486B~1\AppData\Local\Temp\ccRMYmsr.o:main.cpp:(.text+0xaa): undefined reference to `AppWindow::AppWindow()'
C:\Users\486B~1\AppData\Local\Temp\ccRMYmsr.o:main.cpp:(.text+0xbd): undefined reference to `Window::init()'
C:\Users\486B~1\AppData\Local\Temp\ccRMYmsr.o:main.cpp:(.text+0xd4): undefined reference to `Window::isRun()'
C:\Users\486B~1\AppData\Local\Temp\ccRMYmsr.o:main.cpp:(.text+0xe4): undefined reference to `Window::broadcast()'
C:\Users\486B~1\AppData\Local\Temp\ccRMYmsr.o:main.cpp:(.text+0xf9): undefined reference to `AppWindow::~AppWindow()'
C:\Users\486B~1\AppData\Local\Temp\ccRMYmsr.o:main.cpp:(.text+0x119): undefined reference to `AppWindow::~AppWindow()'
C:\Users\486B~1\AppData\Local\Temp\ccRMYmsr.o:main.cpp:(.xdata+0x44): undefined reference to `__gxx_personality_sj0'
collect2.exe: error: ld returned 1 exit status

Код main.cpp:

#include "AppWindow.h"

int main() { AppWindow app; if (app.init()) { while (app.isRun()) { app.broadcast(); } }

return 0;

}

Код Window.cpp:

#include "Window.h"

//Window* window=nullptr;

Window::Window() {

}

LRESULT CALLBACK WndProc(HWND hwnd,UINT msg, WPARAM wparam, LPARAM lparam) { //GetWindowLong(hwnd,) switch (msg) { case WM_CREATE: { // Event fired when the window is created // collected here.. Window* window = (Window*)((LPCREATESTRUCT)lparam)->lpCreateParams; // .. and then stored for later lookup SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)window); window->onCreate(); break; }

case WM_DESTROY:
{
    // Event fired when the window is destroyed
    Window* window =(Window*) GetWindowLongPtr(hwnd, GWLP_USERDATA);
    window->onDestroy();
    ::PostQuitMessage(0);
    break;
}


default:
    return ::DefWindowProc(hwnd, msg, wparam, lparam);
}

return NULL;

}

bool Window::init() {

//Setting up WNDCLASSEX object
WNDCLASSEX wc;
wc.cbClsExtra = NULL;
wc.cbSize = sizeof(WNDCLASSEX);
wc.cbWndExtra = NULL;
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wc.hInstance = NULL;
wc.lpszClassName = "MyWindowClass";
wc.lpszMenuName = "";
wc.style = NULL;
wc.lpfnWndProc = &WndProc;

if (!::RegisterClassEx(&wc)) // If the registration of class will fail, the function will return false
    return false;

/*if (!window)
    window = this;*/

//Creation of the window
m_hwnd=::CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, "MyWindowClass", "DirectX Application", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 1024, 768,
    NULL, NULL, NULL, this);

//if the creation fail return false
if (!m_hwnd) 
    return false;

//show up the window
::ShowWindow(m_hwnd, SW_SHOW);
::UpdateWindow(m_hwnd);




//set this flag to true to indicate that the window is initialized and running
m_is_run = true;



return true;

}

bool Window::broadcast() { MSG msg;

while (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) > 0)
{
    TranslateMessage(&msg);
    DispatchMessage(&msg);
}

this->onUpdate();

Sleep(1);

return true;

}

bool Window::release() { //Destroy the window if (!::DestroyWindow(m_hwnd)) return false;

return true;

}

bool Window::isRun() { return m_is_run; }

void Window::onCreate() { }

void Window::onUpdate() { }

void Window::onDestroy() { m_is_run = false; }

Window::~Window() { }

Код AppWindow.cpp:

#include "AppWindow.h"

AppWindow::AppWindow() { }

AppWindow::~AppWindow() { }

void AppWindow::onCreate() { Window::onCreate();

}

void AppWindow::onUpdate() { Window::onUpdate();

}

void AppWindow::onDestroy() { Window::onDestroy(); }

Код AppWindow.h:

#pragma once
#include "Window.h"

class AppWindow: public Window { public: AppWindow(); ~AppWindow();

    virtual void onCreate() override;
    virtual void onDestroy() override;
    virtual void onUpdate() override;

};

Код Window.h:

#pragma once
#include <Windows.h>

class Window { public: Window(); //Initialize the window bool init(); bool broadcast(); //Release the window bool release(); bool isRun();

//EVENTS
virtual void onCreate();
virtual void onUpdate();
virtual void onDestroy();


~Window();

protected: HWND m_hwnd; bool m_is_run; };

1 Answers1

0

g++ main.cpp Window.cpp AppWindow.cpp -o main.exe