linux c++ netbeans 7.4 opengl问题
Posted
技术标签:
【中文标题】linux c++ netbeans 7.4 opengl问题【英文标题】:linux c++ netbeans 7.4 opengl issue 【发布时间】:2013-11-15 23:19:41 【问题描述】:这是我用来试用 OpenGL 的程序:
#include <cstdlib>
#include <GL/glut.h>
void display()
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set background color to black and opaque
glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer
// Draw a Red 1x1 Square centered at origin
glBegin(GL_QUADS); // Each set of 4 vertices form a quad
glColor3f(1.0f, 0.0f, 0.0f); // Red
glVertex2f(-0.5f, -0.5f); // x, y
glVertex2f( 0.5f, -0.5f);
glVertex2f( 0.5f, 0.5f);
glVertex2f(-0.5f, 0.5f);
glEnd();
glFlush(); // Render now
/* Main function: GLUT runs as a console application starting at main() */
int main(int argc, char** argv)
glutInit(&argc, argv); // Initialize GLUT
glutCreateWindow("OpenGL Setup Test"); // Create a window with the given title
glutInitWindowSize(320, 320); // Set the window's initial width & height
glutInitWindowPosition(50, 50); // Position the window's initial top-left corner
glutDisplayFunc(display); // Register display callback handler for window re-paint
glutMainLoop(); // Enter the infinitely event-processing loop
return 0;
在运行/构建时,我得到以下输出:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/simon/NetBeansProjects/CppApplication_4'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/cppapplication_4
make[2]: Entering directory `/home/simon/NetBeansProjects/CppApplication_4'
mkdir -p build/Debug/GNU-Linux-x86
rm -f build/Debug/GNU-Linux-x86/main.o.d
g++ -c -g -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/cppapplication_4 build/Debug/GNU-Linux-x86/main.o -L/usr/include/GL -lglut -lglfw -lGLEW -lGLU
/usr/bin/ld: build/Debug/GNU-Linux-x86/main.o: undefined reference to symbol 'glVertex2f'
/usr/lib/x86_64-linux-gnu/mesa/libGL.so.1: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/cppapplication_4] Error 1
make[2]: Leaving directory `/home/simon/NetBeansProjects/CppApplication_4'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/simon/NetBeansProjects/CppApplication_4'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 222ms)
关于构建失败的任何想法?根据我的谷歌搜索,它应该可以工作。
我对编程很陌生,但我看到的是“对符号 'glVertex2f' 的未定义引用”,这可能是也可能不是所有问题的中心?
【问题讨论】:
我不确定:-L/usr/include/GL.我不希望在 GL 包含目录中找到 libglut 等。 【参考方案1】:g++ -o dist/Debug/GNU-Linux-x86/cppapplication_4 build/Debug/GNU-Linux-x86/main.o -L/usr/include/GL -lglut -lglfw -lGLEW -lGLU
将-lGL
添加到您的链接器行。
【讨论】:
以上是关于linux c++ netbeans 7.4 opengl问题的主要内容,如果未能解决你的问题,请参考以下文章
netbeans 7.4 和 phonegap sdk 位置