简体   繁体   中英

linux c++ netbeans 7.4 opengl issue

This is a program I am using to try out 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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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