简体   繁体   English

linux c ++ netbeans 7.4 opengl问题

[英]linux c++ netbeans 7.4 opengl issue

This is a program I am using to try out OpenGL: 这是我用来试用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;
}

Upon running/building, I get the following output: 在运行/构建时,我得到以下输出:

"/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)

Any ideas why the build fails? 任何想法为什么构建失败? According to my googling it should work. 根据我的谷歌搜索它应该工作。

I'm very new to programming, but what I can see is "undefined reference to symbol 'glVertex2f'" which may or may not be the center of all problems? 我对编程很新,但我能看到的是“对符号'glVertex2f'的未定义引用”,它可能是也可能不是所有问题的中心?

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添加到链接器行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM