当我尝试编译我的简单OpenGl程序时,我得到了未定义的引用,但我不知道为什么,我虽然设置正确,但我猜不是。有人可以帮我解决我的问题吗?
我的代码:
#include <GL\glew.H>
#include <GLFW\glfw3.h>
int windowWidth = 980;
int windowHeight = 640;
int Main()
{
if (!glfwInit())
return -1;
glfwWindowHint(GLFW_SAMPLES, 4); // AA
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = NULL;
window = glfwCreateWindow(windowWidth, windowHeight, "Window", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
}
控制台消息:
"/C/Development/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/c/Users/Callum/Documents/NetBeansProjects/Game'
"/C/Development/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/game.exe
make.exe[2]: Entering directory `/c/Users/Callum/Documents/NetBeansProjects/Game'
mkdir -p dist/Debug/MinGW-Windows
g++ -o dist/Debug/MinGW-Windows/game build/Debug/MinGW-Windows/main.o -L../../../../../Development/glew\ 1.11.0/lib -L../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw -lglew32 -lglfw3
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(window.c.obj):window.c:(.text+0x5fa): undefined reference to `glClear@4'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(context.c.obj):context.c:(.text+0x41): undefined reference to `glGetIntegerv@8'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(context.c.obj):context.c:(.text+0xb8): undefined reference to `glGetString@4'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(context.c.obj):context.c:(.text+0x608): undefined reference to `glGetString@4'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(context.c.obj):context.c:(.text+0x76f): undefined reference to `glGetIntegerv@8'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(context.c.obj):context.c:(.text+0x7b9): undefined reference to `glGetIntegerv@8'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(context.c.obj):context.c:(.text+0x856): undefined reference to `glGetIntegerv@8'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x30a): undefined reference to `_imp__CreateDCW@16'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x356): undefined reference to `_imp__GetDeviceCaps@8'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x3a2): undefined reference to `_imp__DeleteDC@4'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(win32_gamma.c.obj):win32_gamma.c:(.text+0x7b): undefined reference to `_imp__CreateDCW@16'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(win32_gamma.c.obj):win32_gamma.c:(.text+0x91): undefined reference to `_imp__GetDeviceGammaRamp@8'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(win32_gamma.c.obj):win32_gamma.c:(.text+0x9d): undefined reference to `_imp__DeleteDC@4'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(win32_gamma.c.obj):win32_gamma.c:(.text+0x35b): undefined reference to `_imp__CreateDCW@16'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(win32_gamma.c.obj):win32_gamma.c:(.text+0x36d): undefined reference to `_imp__SetDeviceGammaRamp@8'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(win32_gamma.c.obj):win32_gamma.c:(.text+0x379): undefined reference to `_imp__DeleteDC@4'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x13b): undefined reference to `_imp__DescribePixelFormat@16'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x926): undefined reference to `_imp__DescribePixelFormat@16'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0xa5e): undefined reference to `_imp__DescribePixelFormat@16'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0xa80): undefined reference to `_imp__SetPixelFormat@12'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0xbaf): undefined reference to `_imp__wglMakeCurrent@8'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0xbca): undefined reference to `_imp__wglGetProcAddress@4'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x10d1): undefined reference to `_imp__wglCreateContext@4'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x10ff): undefined reference to `_imp__wglShareLists@8'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x1337): undefined reference to `_imp__wglDeleteContext@4'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x14d1): undefined reference to `_imp__wglMakeCurrent@8'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x1503): undefined reference to `_imp__wglMakeCurrent@8'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x1542): undefined reference to `_imp__SwapBuffers@4'
../../../../../Development/glfw-3.0.4.bin.WIN32/lib-mingw/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x165d): undefined reference to `_imp__wglGetProcAddress@4'
c:/development/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libmingw32.a(main.o):main.c:(.text.startup+0xa7): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
make.exe[2]: *** [dist/Debug/MinGW-Windows/game.exe] Error 1
make.exe[2]: Leaving directory `/c/Users/Callum/Documents/NetBeansProjects/Game'
make.exe[1]: *** [.build-conf] Error 2
make.exe[1]: Leaving directory `/c/Users/Callum/Documents/NetBeansProjects/Game'
make.exe": *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 3s)
以下是我的设置的一些屏幕截图:
http://imgur.com/wqKPVk0,wMgRJR6,mprtp7c,eG8DNug,Qc8Vafp,BLguFq4,l9FXzme
答案 0 :(得分:5)
您需要链接到OpenGL库:libopengl32.a
,因此您要将-lopengl32
添加到构建命令,或opengl32
添加到IDE的库中。您还应该链接到gdi32
。 (-lgdi32
)
答案 1 :(得分:0)
您还必须链接到-lGL
这些符号是OpenGL库的一部分。
答案 2 :(得分:0)
确保在编译期间链接这些库。
对于GCC,添加-lGL -lglew
以链接GL和GLEW库。