This is the OpenGL code:
#include <GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutCreateWindow("Hello,world!");
glutDisplayFunc(display);
glutMainLoop();
}
The error messages are:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/zh/workspace/OpenGL/CppApplication_1'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/cppapplication_1
make[2]: Entering directory `/home/zh/workspace/OpenGL/CppApplication_1'
mkdir -p dist/Debug/GNU-Linux-x86
g++ -lglut -lGLU -lGL -lGLEW -o dist/Debug/GNU-Linux-x86/cppapplication_1 build/Debug/GNU-Linux-x86/main.o -L/usr/lib/x86_64-linux-gnu -Wl,-rpath,/usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/libglut.so /usr/lib/x86_64-linux-gnu/libGLU.so /usr/lib/x86_64-linux-gnu/libGLEW.so /usr/lib/x86_64-linux-gnu/libGLEWmx.so
/usr/bin/ld: build/Debug/GNU-Linux-x86/main.o: undefined reference to symbol 'glClear'
/usr/lib/x86_64-linux-gnu/libGL.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/cppapplication_1] Error 1
make[2]: Leaving directory `/home/zh/workspace/OpenGL/CppApplication_1'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/zh/workspace/OpenGL/CppApplication_1'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 124ms)
At first I had thought this is because the OpenGL version installed is too low, but glClear
is available from OpenGL 1.0 and exists in all versions (see here). This is version information of the OpenGL on my system.
I built the freeglut 2.8.1 and glew 1.10.0 and have them installed in my system:
I included the path to the library and specified needed library in the environment:
Also, I have read related threads in repository: enter link description here, enter link description here, but they don't help.
I'm worn out and really can not find what I am missing to build such a simple OpenGL code. Could you please tell me how to troubleshoot this problem? Thank you.
The environment I am using are: Ubuntu 14.04 (64 bit)+ NetBeans 8.0
A hint: when I commented the glClear out, the program can be built successfully.
Edit: For those who working on windows 7 and encountering similar linking problem (OpenGL function not found), Vishwanath gowda's answer in this thread may help.
Edit2: We know that Windows supports OpenGL poorly, if you are at the same time using Intel's entrance-level integrated graphics card for which intel's driver provides no additional support of OpenGL, you'll have to make a new Mesa's OpenGL libray according to the guide here. This can be done because OpenGL is independent of hardware so can be implemented solely by software (A book claims so). Be careful to use machine=x86_64 if you are working on 64bit Win7. You can check that by observing the output of dumpbin /headers youropengldll.dll|more. You can also check that the functionality of OpenGL on your windows system is enhanced after that using a software "OpenGL Extension Viewer".