0
我在编译我的使用OpenGL的C++应用程序。所有包括在里面,libopengl32.a和libglu.a都在我的MinGW lib文件夹中。我的OpenGL的C++文件看起来是这样的:MinGW找不到OpenGL命令
#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 `[email protected]'
GL.cpp:(.text+0x135): undefined reference to `[email protected]'
GL.cpp:(.text+0x157): undefined reference to `[email protected]'
GL.cpp:(.text+0x182): undefined reference to `[email protected]'
GL.cpp:(.text+0x191): undefined reference to `[email protected]'
GL.cpp:(.text+0x1a0): undefined reference to `[email protected]'
GL.cpp:(.text+0x1c2): undefined reference to `[email protected]'
GL.cpp:(.text+0x1db): undefined reference to `[email protected]'
GL.cpp:(.text+0x1fd): undefined reference to `[email protected]'
GL.cpp:(.text+0x216): undefined reference to `[email protected]'
GL.cpp:(.text+0x238): undefined reference to `[email protected]'
GL.cpp:(.text+0x251): undefined reference to `[email protected]'
GL.cpp:(.text+0x259): undefined reference to `[email protected]'
GL.cpp:(.text+0x25e): undefined reference to `[email protected]'
GL.cpp:(.text+0x282): undefined reference to `[email protected]'
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
你记得链接'opengl32.lib'吗? – Vallentin
它不存在于我的电脑 – Hullu2000
那么,那绝对是主要问题! – Vallentin