Reputation: 357
I am trying to compile a .c file containing c-code for opengl. But I keep getting the following error: Interesting question. undefined reference to 'glClear' undefined reference to 'gluLookAt' undefined reference to 'glLoadIdentity' undefined reference to 'glColor3f' undefined reference to 'glLineWidth' undefined reference to 'glBegin' undefined reference to 'glVertex3d' undefined reference to 'glEnd' etc...
I am pretty sure there is nothing wrong with my source code as it is example code that has been provided to us.
the headers i included:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
How could I fix this issue?
FYI: I am compiling this on ubuntu
Upvotes: 0
Views: 452
Reputation: 162164
Your problem lies here:
my3DTest: clean $(OBJS)
LDOPTS=\
cc -o my3DTest $(CFLAGS) $(OBJS) $(LIBPATH) $(LIBS)
the variable LDOPTS assignment is continued into the next line, due to the backslash (\
), thereby your cc
command is just assigned to that variable. Once that's done make continues by using its standard implicit target rules to build the binary. But since you didn't specify the linker options in a variable that make will use for that implicit rule, it will try to link without these variables.
Makefile, assuming that the sourcefile is names vlucht.c
.
Important Notice: Indentation and whitespace does matter in a Makefile. Improper indentation will corrupt the Makefile!
LDLIBS = -lglut -lGLU -lGL -lXt -lXext -lm
EXE = vlucht
OBJS = vlucht.o
.PHONY: clean
all: $(EXE)
$(EXE): $(OBJS)
clean:
-$(RM) -f $(EXE) $(OBJS)
Upvotes: 3