我正在尝试使用 GLFW 在 netbeans 中设置 openGL,但我无法让库正确链接。我有所有它们应该在的图书馆,我已经尝试改变所有链接的顺序,我只是不知道该怎么做。
这是代码:
// This is a small test application for GLFW.
// The program opens a window (640x480), and renders a spinning colored
// triangle (it is controlled with both the GLFW timer and the mouse).
#include <stdio.h>
#include <stdlib.h>
//#define GLFW_DLL
#include <GL/glfw.h>
int main(void) {
int width, height, x;
double t;
// Initialise GLFW
if (!glfwInit()) {
fprintf(stderr, "Failed to initialize GLFW\n");
exit(EXIT_FAILURE);
}
// Open a window and create its OpenGL context
if (!glfwOpenWindow(640, 480, 0, 0, 0, 0, 0, 0, GLFW_WINDOW)) {
fprintf(stderr, "Failed to open GLFW window\n");
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwSetWindowTitle("Spinning Triangle");
// Ensure we can capture the escape key being pressed below
glfwEnable(GLFW_STICKY_KEYS);
// Enable vertical sync (on cards that support it)
glfwSwapInterval(1);
do {
t = glfwGetTime();
glfwGetMousePos(&x, NULL);
// Get window size (may be different than the requested size)
glfwGetWindowSize(&width, &height);
// Special case: avoid division by zero below
height = height > 0 ? height : 1;
glViewport(0, 0, width, height);
// Clear color buffer to black
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
// Select and setup the projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(65.0f, (GLfloat) width / (GLfloat) height, 1.0f, 100.0f);
// Select and setup the modelview matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0f, 1.0f, 0.0f, // Eye-position
0.0f, 20.0f, 0.0f, // View-point
0.0f, 0.0f, 1.0f); // Up-vector
// Draw a rotating colorful triangle
glTranslatef(0.0f, 14.0f, 0.0f);
glRotatef(0.3f * (GLfloat) x + (GLfloat) t * 100.0f, 0.0f, 0.0f, 1.0f);
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-5.0f, 0.0f, -4.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(5.0f, 0.0f, -4.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(0.0f, 0.0f, 6.0f);
glEnd();
// Swap buffers
glfwSwapBuffers();
}// Check if the ESC key was pressed or the window was closed
while (glfwGetKey(GLFW_KEY_ESC) != GLFW_PRESS &&
glfwGetWindowParam(GLFW_OPENED));
// Close OpenGL window and terminate GLFW
glfwTerminate();
exit(EXIT_SUCCESS);
}
这是输出/错误:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/c/Users/cseat/Documents/NetBeansProjects/cs335'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/cs335.exe
make[2]: Entering directory `/c/Users/cseat/Documents/NetBeansProjects/cs335'
mkdir -p build/Debug/MinGW-Windows
rm -f build/Debug/MinGW-Windows/triangle.o.d
gcc.exe -c -g -I/C/MinGW/include/GL -I/C/MinGW/include -I/C/GLFW/glfw-
2.7.8/include/GL -MMD -MP -MF build/Debug/MinGW-Windows/triangle.o.d -o
build/Debug/MinGW-Windows/triangle.o triangle.c
mkdir -p dist/Debug/MinGW-Windows
gcc.exe -o dist/Debug/MinGW-Windows/cs335 build/Debug/MinGW-Windows/triangle.o -
L/C/MinGW/lib -L/C/GLFW/glfw-2.7.8/lib -lmingw32 -lkernel32 -luser32 -lgdi32 -lglu32 -
lopengl32 -lglfw -lglfwdll
make[2]: Leaving directory `/c/Users/cseat/Documents/NetBeansProjects/cs335'
build/Debug/MinGW-Windows/triangle.o: In function `main':
C:/Users/cseat/Documents/NetBeansProjects/cs335/triangle.c:17: undefined reference to
`glfwInit'
C:/Users/cseat/Documents/NetBeansProjects/cs335/triangle.c:23: undefined reference to
`glfwOpenWindow'
C:/Users/cseat/Documents/NetBeansProjects/cs335/triangle.c:26: undefined reference to
`glfwTerminate'
C:/Users/cseat/Documents/NetBeansProjects/cs335/triangle.c:30: undefined reference to
`glfwSetWindowTitle'
C:/Users/cseat/Documents/NetBeansProjects/cs335/triangle.c:33: undefined reference to
`glfwEnable'
make[1]: Leaving directory `/c/Users/cseat/Documents/NetBeansProjects/cs335'
C:/Users/cseat/Documents/NetBeansProjects/cs335/triangle.c:36: undefined reference to
`glfwSwapInterval'
C:/Users/cseat/Documents/NetBeansProjects/cs335/triangle.c:39: undefined reference to
`glfwGetTime'
C:/Users/cseat/Documents/NetBeansProjects/cs335/triangle.c:40: undefined reference to
`glfwGetMousePos'
C:/Users/cseat/Documents/NetBeansProjects/cs335/triangle.c:43: undefined reference to
`glfwGetWindowSize'
C:/Users/cseat/Documents/NetBeansProjects/cs335/triangle.c:79: undefined reference to
`glfwSwapBuffers'
C:/Users/cseat/Documents/NetBeansProjects/cs335/triangle.c:81: undefined reference to
`glfwGetKey'
C:/Users/cseat/Documents/NetBeansProjects/cs335/triangle.c:81: undefined reference to
`glfwGetWindowParam'
C:/Users/cseat/Documents/NetBeansProjects/cs335/triangle.c:86: undefined reference to
`glfwTerminate'
collect2: ld returned 1 exit status
make[2]: * [dist/Debug/MinGW-Windows/cs335.exe] Error 1
make[1]: * [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 866ms)
以下是所有设置和链接的屏幕截图: