簡體   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