Netbeans抱怨未定义的OpenGL引用

时间:2014-12-25 17:14:10

标签: c++ opengl netbeans glfw

我对c ++和OpenGL很陌生,所以我不确定100%我在做什么......

所以,我从This page复制了以下代码:

#include <GLFW/glfw3.h>

int main(void) {
    GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if (!window) {
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window)) {
        /* Render here */

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}

当我在netbeans中运行它时,我得到以下错误:

"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/ryan/NetBeansProjects/Test3D'
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/test3d
make[2]: Entering directory `/home/ryan/NetBeansProjects/Test3D'
mkdir -p build/Debug/GNU-Linux-x86
rm -f "build/Debug/GNU-Linux-x86/main.o.d"
g++    -c -g `pkg-config --cflags glfw3` `pkg-config --cflags x11`   -MMD -MP -MF "build/Debug/GNU-Linux-x86/main.o.d" -o build/Debug/GNU-Linux-x86/main.o main.cpp
mkdir -p dist/Debug/GNU-Linux-x86
g++     -o dist/Debug/GNU-Linux-x86/test3d build/Debug/GNU-Linux-x86/main.o `pkg-config --libs glfw3` `pkg-config --libs x11`  
/usr/local/lib/libglfw3.a(context.c.o): In function `parseGLVersion':
context.c:(.text+0x53): undefined reference to `glGetString'
/usr/local/lib/libglfw3.a(context.c.o): In function `_glfwRefreshContextAttribs':
context.c:(.text+0x8d3): undefined reference to `glGetIntegerv'
context.c:(.text+0x956): undefined reference to `glGetIntegerv'
context.c:(.text+0x9c9): undefined reference to `glGetIntegerv'
context.c:(.text+0xa1e): undefined reference to `glGetIntegerv'
/usr/local/lib/libglfw3.a(context.c.o): In function `glfwExtensionSupported':
context.c:(.text+0xd29): undefined reference to `glGetString'
context.c:(.text+0xd88): undefined reference to `glGetIntegerv'
/usr/local/lib/libglfw3.a(window.c.o): In function `glfwCreateWindow':
window.c:(.text+0x724): undefined reference to `glClear'
/usr/local/lib/libglfw3.a(x11_gamma.c.o): In function `_glfwInitGammaRamp':
x11_gamma.c:(.text+0x49): undefined reference to `XRRGetScreenResources'
x11_gamma.c:(.text+0x6a): undefined reference to `XRRGetCrtcGammaSize'
x11_gamma.c:(.text+0x81): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_gamma.c.o): In function `_glfwPlatformGetGammaRamp':
x11_gamma.c:(.text+0xce): undefined reference to `XRRGetCrtcGammaSize'
x11_gamma.c:(.text+0xf1): undefined reference to `XRRGetCrtcGamma'
x11_gamma.c:(.text+0x17d): undefined reference to `XRRFreeGamma'
x11_gamma.c:(.text+0x1a5): undefined reference to `XF86VidModeGetGammaRampSize'
x11_gamma.c:(.text+0x1f3): undefined reference to `XF86VidModeGetGammaRamp'
/usr/local/lib/libglfw3.a(x11_gamma.c.o): In function `_glfwPlatformSetGammaRamp':
x11_gamma.c:(.text+0x231): undefined reference to `XRRAllocGamma'
x11_gamma.c:(.text+0x2cd): undefined reference to `XRRSetCrtcGamma'
x11_gamma.c:(.text+0x2d9): undefined reference to `XRRFreeGamma'
x11_gamma.c:(.text+0x321): undefined reference to `XF86VidModeSetGammaRamp'
/usr/local/lib/libglfw3.a(x11_init.c.o): In function `initExtensions':
x11_init.c:(.text+0x15f2): undefined reference to `XF86VidModeQueryExtension'
x11_init.c:(.text+0x1611): undefined reference to `XRRQueryExtension'
x11_init.c:(.text+0x163b): undefined reference to `XRRQueryVersion'
x11_init.c:(.text+0x16cf): undefined reference to `XIQueryVersion'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwSetVideoMode':
x11_monitor.c:(.text+0x176): undefined reference to `XRRGetScreenResources'
x11_monitor.c:(.text+0x19b): undefined reference to `XRRGetCrtcInfo'
x11_monitor.c:(.text+0x1bd): undefined reference to `XRRGetOutputInfo'
x11_monitor.c:(.text+0x3c3): undefined reference to `XRRSetCrtcConfig'
x11_monitor.c:(.text+0x3cf): undefined reference to `XRRFreeOutputInfo'
x11_monitor.c:(.text+0x3db): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0x3e7): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwRestoreVideoMode':
x11_monitor.c:(.text+0x432): undefined reference to `XRRGetScreenResources'
x11_monitor.c:(.text+0x457): undefined reference to `XRRGetCrtcInfo'
x11_monitor.c:(.text+0x4cc): undefined reference to `XRRSetCrtcConfig'
x11_monitor.c:(.text+0x4d8): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0x4e4): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetMonitors':
x11_monitor.c:(.text+0x543): undefined reference to `XRRGetScreenResources'
x11_monitor.c:(.text+0x560): undefined reference to `XRRGetOutputPrimary'
x11_monitor.c:(.text+0x5b8): undefined reference to `XRRGetCrtcInfo'
x11_monitor.c:(.text+0x5d3): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0x642): undefined reference to `XRRGetOutputInfo'
x11_monitor.c:(.text+0x65f): undefined reference to `XRRFreeOutputInfo'
x11_monitor.c:(.text+0x66b): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0x6ff): undefined reference to `XRRFreeOutputInfo'
x11_monitor.c:(.text+0x70b): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0x72f): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetMonitorPos':
x11_monitor.c:(.text+0x8b3): undefined reference to `XRRGetScreenResources'
x11_monitor.c:(.text+0x8d8): undefined reference to `XRRGetCrtcInfo'
x11_monitor.c:(.text+0x910): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0x91c): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetVideoModes':
x11_monitor.c:(.text+0x9be): undefined reference to `XRRGetScreenResources'
x11_monitor.c:(.text+0x9e0): undefined reference to `XRRGetOutputInfo'
x11_monitor.c:(.text+0xb6d): undefined reference to `XRRFreeOutputInfo'
x11_monitor.c:(.text+0xb79): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetVideoMode':
x11_monitor.c:(.text+0xc51): undefined reference to `XRRGetScreenResources'
x11_monitor.c:(.text+0xc76): undefined reference to `XRRGetCrtcInfo'
x11_monitor.c:(.text+0xccb): undefined reference to `XRRFreeCrtcInfo'
x11_monitor.c:(.text+0xcd7): undefined reference to `XRRFreeScreenResources'
/usr/local/lib/libglfw3.a(x11_window.c.o): In function `createWindow':
x11_window.c:(.text+0x6dc): undefined reference to `XISelectEvents'
x11_window.c:(.text+0x71e): undefined reference to `XRRSelectInput'
/usr/local/lib/libglfw3.a(x11_window.c.o): In function `processEvent':
x11_window.c:(.text+0x1784): undefined reference to `XRRUpdateConfiguration'
/usr/local/lib/libglfw3.a(glx_context.c.o): In function `getFBConfigAttrib':
glx_context.c:(.text+0x4d): undefined reference to `glXGetFBConfigAttrib'
/usr/local/lib/libglfw3.a(glx_context.c.o): In function `chooseFBConfig':
glx_context.c:(.text+0x7a): undefined reference to `glXGetClientString'
glx_context.c:(.text+0xe5): undefined reference to `glXGetFBConfigs'
/usr/local/lib/libglfw3.a(glx_context.c.o): In function `createLegacyContext':
glx_context.c:(.text+0x41f): undefined reference to `glXCreateNewContext'
/usr/local/lib/libglfw3.a(glx_context.c.o): In function `_glfwInitContextAPI':
glx_context.c:(.text+0x434): undefined reference to `pthread_key_create'
glx_context.c:(.text+0x46f): undefined reference to `glXQueryExtension'
glx_context.c:(.text+0x4aa): undefined reference to `glXQueryVersion'
/usr/local/lib/libglfw3.a(glx_context.c.o): In function `_glfwTerminateContextAPI':
glx_context.c:(.text+0x69e): undefined reference to `pthread_key_delete'
/usr/local/lib/libglfw3.a(glx_context.c.o): In function `_glfwCreateContext':
glx_context.c:(.text+0x780): undefined reference to `glXGetVisualFromFBConfig'
/usr/local/lib/libglfw3.a(glx_context.c.o): In function `_glfwDestroyContext':
glx_context.c:(.text+0xda8): undefined reference to `glXDestroyContext'
/usr/local/lib/libglfw3.a(glx_context.c.o): In function `_glfwPlatformMakeContextCurrent':
glx_context.c:(.text+0xdf4): undefined reference to `glXMakeCurrent'
glx_context.c:(.text+0xe0f): undefined reference to `glXMakeCurrent'
glx_context.c:(.text+0xe23): undefined reference to `pthread_setspecific'
/usr/local/lib/libglfw3.a(glx_context.c.o): In function `_glfwPlatformGetCurrentContext':
glx_context.c:(.text+0xe36): undefined reference to `pthread_getspecific'
/usr/local/lib/libglfw3.a(glx_context.c.o): In function `_glfwPlatformSwapBuffers':
glx_context.c:(.text+0xe61): undefined reference to `glXSwapBuffers'
/usr/local/lib/libglfw3.a(glx_context.c.o): In function `_glfwPlatformExtensionSupported':
glx_context.c:(.text+0xf04): undefined reference to `glXQueryExtensionsString'
/usr/local/lib/libglfw3.a(glx_context.c.o): In function `_glfwPlatformGetProcAddress':
glx_context.c:(.text+0xf4c): undefined reference to `glXGetProcAddressARB'
collect2: error: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/test3d] Error 1
make[2]: Leaving directory `/home/ryan/NetBeansProjects/Test3D'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/ryan/NetBeansProjects/Test3D'
make: *** [.build-impl] Error 2

我不确定这意味着100%,但我假设我没有将一些软件包添加到项目中。

但是,我可以按照以下步骤安装并运行程序:https://stackoverflow.com/a/17772217/1778465链接到此处http://www.glfw.org/docs/3.0/quick.html,所以我知道GLFW可以正常工作。

1 个答案:

答案 0 :(得分:1)

您的构建设置缺少指定链接与OpenGL接口库。编译时为

  • Windows→opengl32.lib-lopengl32
  • X11 / GLX(Linux / * BSD / * Solaris)→libGL.so -lGL
  • MacOS X→OpenGL Framework→-framework OpenGL