繁体   English   中英

MinGW找不到OpenGL命令

[英]MinGW can't find OpenGL commands

我正在尝试编译使用OpenGL的C ++应用程序。 全部包含在内,并且libopengl32.a和libglu.a都在我的MinGW lib文件夹中。 我的OpenGL c ++文件如下所示:

#include <GL/gl.h>
#include <GL/glu.h>
#include <pthread.h>
#include <windows.h>

#include "GL.h"

//using namespace std;

HDC hDC;
PIXELFORMATDESCRIPTOR pfd;
HGLRC hRC;

BOOL ren = false;
pthread_t t;

void initGL(HWND hWnd)
{
    hDC = GetDC(hWnd);
    ReleaseDC(hWnd, hDC);

    pfd.nSize = sizeof(pfd);
    pfd.nVersion = 1;
    pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
    pfd.iPixelType = PFD_TYPE_RGBA;
    pfd.cColorBits = 24;
    pfd.cDepthBits = 16;
    pfd.iLayerType = PFD_MAIN_PLANE;
    int iFormat = ChoosePixelFormat(hDC, &pfd);
    SetPixelFormat(hDC, iFormat, &pfd);

    hRC = wglCreateContext(hDC);
}

void destroyGL()
{
    wglDeleteContext(hRC);
}

void renderGL()
{
    wglMakeCurrent(hDC, hRC);

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    glBegin( GL_TRIANGLES );
    glColor3f( 1.0f, 0.0f, 0.0f ); glVertex2f( 0.0f, 1.0f );
    glColor3f( 0.0f, 1.0f, 0.0f ); glVertex2f( 0.87f, -0.5f );
    glColor3f( 0.0f, 0.0f, 1.0f ); glVertex2f( -0.87f, -0.5f );
    glEnd();
    glPopMatrix();

    SwapBuffers(hDC);

    wglMakeCurrent(NULL, NULL);
}

void *RenderLoop(void *args)
{
    while(ren)
    {
        renderGL();
    }
    return 0;
}

void StartRender()
{
    ren = true;
    pthread_create(&t, NULL, RenderLoop, NULL);
}

void StopRender()
{
    ren = false;
}

代码看起来不错,但是当我编译它时,我得到了:

GL.cpp:(.text+0x1c): undefined reference to `_imp____glutInitWithExit
GL.cpp:(.text+0x3e): undefined reference to `_imp____glutCreateWindow
GL.cpp:(.text+0x60): undefined reference to `_imp____glutCreateMenuWi
GL.cpp:(.text+0x118): undefined reference to `wglCreateContext@4'
GL.cpp:(.text+0x135): undefined reference to `wglDeleteContext@4'
GL.cpp:(.text+0x157): undefined reference to `wglMakeCurrent@8'
GL.cpp:(.text+0x182): undefined reference to `glClearColor@16'
GL.cpp:(.text+0x191): undefined reference to `glClear@4'
GL.cpp:(.text+0x1a0): undefined reference to `glBegin@4'
GL.cpp:(.text+0x1c2): undefined reference to `glColor3f@12'
GL.cpp:(.text+0x1db): undefined reference to `glVertex2f@8'
GL.cpp:(.text+0x1fd): undefined reference to `glColor3f@12'
GL.cpp:(.text+0x216): undefined reference to `glVertex2f@8'
GL.cpp:(.text+0x238): undefined reference to `glColor3f@12'
GL.cpp:(.text+0x251): undefined reference to `glVertex2f@8'
GL.cpp:(.text+0x259): undefined reference to `glEnd@0'
GL.cpp:(.text+0x25e): undefined reference to `glPopMatrix@0'
GL.cpp:(.text+0x282): undefined reference to `wglMakeCurrent@8'
GL.cpp:(.text+0x2dd): undefined reference to `_imp__pthread_create'

我这样编译我的代码:

windres res.rc -o res.o
g++ -static -static-libgcc -static-libstdc++ -s -mwindows -c win.cpp GL.cpp
g++ -static -static-libgcc -static-libstdc++ -s -mwindows -lopengl32 -lglu32 win.o GL.o res.o -o bin/win.exe

似乎g ++找不到2个库之一。 尝试在带-L选项的g ++命令中显式提供所需的.a文件目录。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM