I am a university student trying to setup my home desktop with Ubuntu 13.10 for OpenGL development. I have installed all of these libraries. Our first assignment was to write a simple program and a generic makefile that would work for the rest of the semester. This worked perfectly in the Computer Labs on campus.
My main.c file:
# include <GL/glut.h>
void display();
int main (int argc, char ** argv)
{
glutInit(&argc , argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
glutInitWindowSize(640 , 480) ;
glutCreateWindow("Practical 1");
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
void display()
{
glClearColor(0.0 , 0.0 , 1.0 , 1.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glFlush();
glutSwapBuffers();
}
And my makefile:
STUDENT_NUMBER = 1234567890
TASK = practical
NUMBER =1
OBJECTS=$(addsuffix .o,$(basename $(shell ls *.C)))
WARNING_FLAGS = -Wall -Wextra -Weffc++ -Winit -self -Wmissing -include -dirs -Wswitch -default -Wswitch -enum -Wunused -parameter -Wstrict -overflow=5 -Wfloat -equal -Wshadow -Wc++0x -compat -Wconversion -Wsign -conversion-Wmissing -declarations -Wstrict -null -sentinel -Woverloaded -virtual -Wsign -promo -Werror -pedantic -Wcast -qual
FORMATTING_FLAGS = -fno -pretty -templates -fmessage -length=80 -fdiagnostics -show -option
CFLAGS = ${WARNING_FLAGS} ${FORMATTING_FLAGS} g -std=c++0x -pipe -frepo
LDLIBS = -lGL -lglut -lGLEW -lGLU -lX11 -lXi -lm -lrt -lpng
LDFLAGS =
CC = g++
TARGET = main
all: ${OBJECTS}
${CC} ${LDFLAGS} ${LDLIBS} $^ -o ${TARGET}
%.o: %.c
${CC} ${CFLAGS} -c ${LDFLAGS} $< -o $@
makefile.dep: *.[Ch]
for i in *.C; do gcc -MM "$${i}"; done > $@
include makefile.dep
clean:
rm ${OBJECTS} *.rpo *.gch makefile.dep ${TARGET}
tar:
make clean; tar -cvjf ${STUDENT_NUMBER}_${TASK}_${NUMBER}.tar.bz2 *
When trying to compile on my home desktop I get these erors:
g++ -lGL -lglut -lGLEW -lGLU -lX11 -lXi -lm -lrt -lpng main.o -o main
main.o: In function `main':
main.C:(.text+0x1e): undefined reference to `glutInit'
main.C:(.text+0x28): undefined reference to `glutInitDisplayMode'
main.C:(.text+0x37): undefined reference to `glutInitWindowSize'
main.C:(.text+0x41): undefined reference to `glutCreateWindow'
main.C:(.text+0x4b): undefined reference to `glutDisplayFunc'
main.C:(.text+0x50): undefined reference to `glutMainLoop'
main.o: In function `display()':
main.C:(.text+0x76): undefined reference to `glClearColor'
main.C:(.text+0x80): undefined reference to `glClear'
main.C:(.text+0x85): undefined reference to `glFlush'
main.C:(.text+0x8a): undefined reference to `glutSwapBuffers'
collect2: error: ld returned 1 exit status
make: *** [all] Error 1
I think I might be missing some library or something.