使用OpenGL时未解决的外部错误

时间:2014-07-14 16:07:26

标签: c++ winapi opengl hyperlink externals

我对C ++的了解非常基础,我无法在任何地方找到解决问题的方法。

我正在尝试编写一个简单的OpenGL程序,但我似乎无法让自己开始。这是我的主要文件:

#include <Windows.h>
#include <gl/GL.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>

HINSTANCE hInst;

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{   
    const TCHAR szWindowClass[] = _T("gl_previewer");
    const TCHAR szWindowTitle[] = _T("GL Previewer");

    WNDCLASSEX wcex;

    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style          = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc    = WndProc;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = hInstance;
    wcex.hIcon          = LoadIcon(NULL, MAKEINTRESOURCE(IDI_APPLICATION));
    wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW);
    wcex.lpszMenuName   = NULL;
    wcex.lpszClassName  = szWindowClass;
    wcex.hIconSm        = NULL;

    if (!RegisterClassEx(&wcex))
    {
        MessageBox(NULL, _T("Failed to register window."), szWindowTitle, NULL);
        return 1;
    }

    HWND hWnd = CreateWindow(szWindowClass, szWindowTitle, WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME & ~WS_MAXIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, 1280, 720, NULL, NULL, hInstance, NULL);

    if (!hWnd)
    {
        MessageBox(NULL, _T("Failed to create window."), szWindowTitle, NULL);
        return 1;
    }

    hInst = hInstance;

    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);

    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return (int) msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {   
        static HGLRC hrc;
        static HDC hdc;

    case WM_CREATE:
        hdc = GetDC(hWnd);
        hrc = wglCreateContext(hdc);
        wglMakeCurrent(hdc, hrc);
        break;
    case WM_CLOSE:
        DestroyWindow(hWnd);
        break;
    case WM_DESTROY:
        wglMakeCurrent(hdc, NULL);
        wglDeleteContext(hrc);
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, msg, wParam, lParam);
    }
    return 0;
}

编译时,这给了我这些错误:

Error   15  error LNK1120: 14 unresolved externals  C:\Users\Aaron\documents\visual studio 2010\Projects\GLViewer\Debug\GLViewer.exe
Error   6   error LNK2019: unresolved external symbol __imp__CreateWindowExW@48 referenced in function _WinMain@16  C:\Users\Aaron\documents\visual studio 2010\Projects\GLViewer\GLViewer\main.obj
Error   11  error LNK2019: unresolved external symbol __imp__DefWindowProcW@16 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)  C:\Users\Aaron\documents\visual studio 2010\Projects\GLViewer\GLViewer\main.obj
Error   13  error LNK2019: unresolved external symbol __imp__DestroyWindow@4 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)    C:\Users\Aaron\documents\visual studio 2010\Projects\GLViewer\GLViewer\main.obj
Error   1   error LNK2019: unresolved external symbol __imp__DispatchMessageW@4 referenced in function _WinMain@16  C:\Users\Aaron\documents\visual studio 2010\Projects\GLViewer\GLViewer\main.obj
Error   14  error LNK2019: unresolved external symbol __imp__GetDC@4 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)    C:\Users\Aaron\documents\visual studio 2010\Projects\GLViewer\GLViewer\main.obj
Error   3   error LNK2019: unresolved external symbol __imp__GetMessageW@16 referenced in function _WinMain@16  C:\Users\Aaron\documents\visual studio 2010\Projects\GLViewer\GLViewer\main.obj
Error   9   error LNK2019: unresolved external symbol __imp__LoadCursorW@8 referenced in function _WinMain@16   C:\Users\Aaron\documents\visual studio 2010\Projects\GLViewer\GLViewer\main.obj
Error   10  error LNK2019: unresolved external symbol __imp__LoadIconW@8 referenced in function _WinMain@16 C:\Users\Aaron\documents\visual studio 2010\Projects\GLViewer\GLViewer\main.obj
Error   7   error LNK2019: unresolved external symbol __imp__MessageBoxW@16 referenced in function _WinMain@16  C:\Users\Aaron\documents\visual studio 2010\Projects\GLViewer\GLViewer\main.obj
Error   12  error LNK2019: unresolved external symbol __imp__PostQuitMessage@4 referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z)  C:\Users\Aaron\documents\visual studio 2010\Projects\GLViewer\GLViewer\main.obj
Error   8   error LNK2019: unresolved external symbol __imp__RegisterClassExW@4 referenced in function _WinMain@16  C:\Users\Aaron\documents\visual studio 2010\Projects\GLViewer\GLViewer\main.obj
Error   5   error LNK2019: unresolved external symbol __imp__ShowWindow@8 referenced in function _WinMain@16    C:\Users\Aaron\documents\visual studio 2010\Projects\GLViewer\GLViewer\main.obj
Error   2   error LNK2019: unresolved external symbol __imp__TranslateMessage@4 referenced in function _WinMain@16  C:\Users\Aaron\documents\visual studio 2010\Projects\GLViewer\GLViewer\main.obj
Error   4   error LNK2019: unresolved external symbol __imp__UpdateWindow@4 referenced in function _WinMain@16  C:\Users\Aaron\documents\visual studio 2010\Projects\GLViewer\GLViewer\main.obj

在我的项目属性中,我已经链接了opengl32.lib库。 感谢您提前提供任何帮助!

0 个答案:

没有答案