0

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

1 Answer 1

3

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)
Sign up to request clarification or add additional context in comments.

8 Comments

so what do you suggest? Should I just remove the backslash? Because strangely that worked previously fine for previous pieces of code..
@privetDruzia: First things first I suggest you learn how Makefiles work and the makefile syntax. And I recommend removing the line `LDOPTS=` because it makes zero sense.
ok thanks for your critics... I removed LDOPTS, didn't solve anything. So I have a problem and your answer to my problem "just go and learn" and you didn't solve my issue, very usefull...
@privetDruzia: I don't want to be rude, but the problem I see is, that you simply copy'n'pasted your Makefile from various sources, without actually comprehending what's going on. The same goes for your linker problem. In fact your specific question has been asked countless times on StackOverflow, your particular flavour just adds Makefiles into the mix. For example your Makefile has the CFLAGS variable expansion in the wrong place (it belongs into the compilation phase, not the linking phase). The order of libraries as passed to the linker matters.
@privetDruzia: See my answer update. I added a fixed Makefile that will get the job done (assuming that your source file is name vlucht.c) you may rename to your desire.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.