gpt4 book ai didi

c++ - MinGW 找不到 OpenGL 命令

转载 作者:行者123 更新时间:2023-11-28 07:09:37 25 4
gpt4 key购买 nike

我正在尝试编译使用 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 文件的目录。

关于c++ - MinGW 找不到 OpenGL 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21219215/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com