2013-10-02 78 views
1

我试图编译我的Win32,OpenGL的程序在Visual Studio 2012,我不断收到此错误:OpenGL中,的Visual C++ 2012编译错误

Error 1 error LNK2019: unresolved external symbol [email protected] referenced in function [email protected] C:\Users\Chief\Documents\Programming\C++\Projects\Practice\Practice\WinMain.obj Practice 

Error 2 error LNK1120: 1 unresolved externals C:\Users\Chief\Documents\Programming\C++\Projects\Practice\Debug\Practice.exe 1 1 Practice 

这里是我的代码:

#define WIN32_LEAN_AND_MEAN 

#include <Windows.h> 

#include <gl/GL.h> 

HWND hwnd; 
int clientWidth = 800; 
int clientHeight = 600; 

bool InitMainWindow(HINSTANCE hInstance); 
LRESULT CALLBACK MsgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); 

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) 
{ 
    if(!InitMainWindow(hInstance)) 
    { 
     return 1; 
    } 
    MSG msg = {0}; 
    while(WM_QUIT != msg.message) 
    { 
     if(PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)) 
     { 
      TranslateMessage(&msg); 
      DispatchMessage(&msg); 
     } 
     else 
     { 
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
      //This is where all my updating and rendering stuff will go 
     } 
    } 

    return static_cast<int>(msg.wParam); 
} 

bool InitMainWindow(HINSTANCE hInstance) 
{ 
    WNDCLASSEX wcex; 
    ZeroMemory(&wcex, sizeof(WNDCLASSEX)); 
    wcex.cbClsExtra = 0; 
    wcex.cbWndExtra = 0; 
    wcex.cbSize = sizeof(WNDCLASSEX); 
    wcex.style = CS_HREDRAW | CS_VREDRAW; 
    wcex.hInstance = hInstance; 
    wcex.lpfnWndProc = MsgProc; 
    wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION); 
    wcex.hCursor = LoadCursor(NULL, IDC_ARROW); 
    wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); 
    wcex.lpszClassName = "Project2DClass"; 
    wcex.lpszMenuName = NULL; 
    wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION); 

    if(!RegisterClassEx(&wcex)) 
    { 
     MessageBox(NULL, "Failed to register window class", NULL, NULL); 
     return false; 
    } 

    RECT r = { 0, 0, clientWidth, clientHeight }; 
    DWORD style = WS_OVERLAPPEDWINDOW; 
    AdjustWindowRect(&r, style, false); 
    int width = r.right - r.left; 
    int height = r.bottom - r.top; 
    int x = GetSystemMetrics(SM_CXSCREEN)/2 - width/2; 
    int y = GetSystemMetrics(SM_CYSCREEN)/2 - height/2; 

    hwnd = CreateWindow("Project2DClass", "Project 2D", style, x, y, width, height, NULL, NULL, hInstance, NULL); 
    if(!hwnd) 
    { 
     MessageBox(NULL, "Failed to create window", NULL, NULL); 
     return false; 
    } 

    ShowWindow(hwnd, SW_SHOW); 

    return true; 
} 

LRESULT CALLBACK MsgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) 
{ 
    switch(msg) 
    { 
    case WM_DESTROY: 
     PostQuitMessage(0); 
     return 0; 
    } 

    return DefWindowProc(hwnd, msg, wParam, lParam); 
} 

有人能告诉我如何解决这个问题以及我做错了什么吗?并再次使用微软Visual Studio 2012和OpenGL

回答

3

你在链接步骤缺少一个或多个库:openGL32.lib

你需要做以下

添加“opengl32.lib”到项目属性 - >配置属性 - >连接器 - >输入 - >额外的依赖关系。

+0

在哪里,虽然 – kzolp67

+1

这些库应安装,当你安装的OpenGL路径设置这些库。实际位置将是system32或其安装目录。 –

+0

发现它,它现在工作正常 – kzolp67

1

您需要链接到opengl32库,可能只是opengl32.lib

又见documentation(但请记住,这是技术上的OpenGL 1.1,其MS支持,任何新的功能将需要一些其他的方式来照顾,像GLEW,供过于求等书面...)