PDA

View Full Version : problem compiling/linking on linux



mox601
06-03-2007, 03:05 AM
hello everyone, i'm matteo and i'm kinda new with opengl/glut so be patient...

i'm writing a program and everything went fine until i added the project a new file, objects.c and .h in which i have some functions to call from palazzo.c, the one with main().

i think i made a mess with the Makefile and with includes of libraries: i'm posting my code so i hope someone can help!

makefile:

#ottimizza livello 2 ed includi simboli debugging
OBJECTS=palazzo.o objects.o
CFLAGS=-O2 -g
INCDIR=
LINKLIBS=-lglut -lGLU -lGL -lm

palazzo: palazzo.o objects.o
$(CC) $(CFLAGS) $(LINKLIBS) objects.o palazzo.o -o palazzo

%.o: %.c
$(CC) $(CFLAGS) $(LINKLIBS) -c $< -o $@


clean:
rm -f *.o palazzo objects
@echo "clean done"palazzo.c (just the include)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <GL/glut.h>
#include <GL/glu.h>

#include "objects.h"objects.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <GL/glut.h>

#include "objects.h"objects.h

#ifndef _objects
#define _objects
#endifthe error i get when launcing make is the following:


cc -O2 -g -lglut -lGLU -lGL -lm -c palazzo.c -o palazzo.o
palazzo.c: In function ‘main’:
palazzo.c:234: error: ‘Glfloat’ undeclared (first use in this function)
palazzo.c:234: error: (Each undeclared identifier is reported only once
palazzo.c:234: error: for each function it appears in.)
palazzo.c:234: error: expected ‘;’ before ‘diffuseLight’
palazzo.c:235: error: expected ‘;’ before ‘specularLight’
palazzo.c:236: error: expected ‘;’ before ‘position’
palazzo.c:236:25: error: invalid suffix "f" on integer constant
palazzo.c:236:30: error: invalid suffix "f" on integer constant
palazzo.c:236:35: error: invalid suffix "f" on integer constant
palazzo.c:240: error: ‘diffuseLight’ undeclared (first use in this function)
palazzo.c:241: error: ‘specularLight’ undeclared (first use in this function)
palazzo.c:242: error: ‘position’ undeclared (first use in this function)
make: *** [palazzo.o] Error 1 tell me if i have to paste some other lines!
thanxx!

memfr0b
06-03-2007, 04:23 AM
The first error (and probably some of the following) is caused by a typo in the type name. The correct type is GLfloat (notice the uppercase L), not Glfloat.

The invalid suffix errors are caused by not omitting the decimal dot in float literals of integral value. For example the value 123 as a float literal is "123.0f" or "123.f". "123f" is not a valid float literal.

mox601
06-03-2007, 04:33 AM
thanks!!
(i won't ever copy/paste code from the internet... )
now this is the output i get with "make"
are there some problems with flags/includes in the makefile?


cc -O2 -g -lglut -lGLU -lGL -lm -c palazzo.c -o palazzo.o
cc: -lglut: linker input file unused because linking not done
cc: -lGLU: linker input file unused because linking not done
cc: -lGL: linker input file unused because linking not done
cc: -lm: linker input file unused because linking not done
cc -O2 -g -lglut -lGLU -lGL -lm -c objects.c -o objects.o
cc: -lglut: linker input file unused because linking not done
cc: -lGLU: linker input file unused because linking not done
cc: -lGL: linker input file unused because linking not done
cc: -lm: linker input file unused because linking not done
cc -O2 -g -lglut -lGLU -lGL -lm objects.o palazzo.o -o palazzo

predaeus
06-03-2007, 06:09 AM
Actually it looks as if it succeeded and compiled/linked into a binary. You should be able to run "./palazzo".

The messages "linker input file unused because linking not done" are just info messages, telling you that not all libraries specified have been used for linking this object file because it does not need it (e.g. some .c file with code for loading texture data from a file that does not use any opengl functions, would not need -lGL). That is because you have specified your make file to compile/link every object file (.o) against every library all the time. You could prevent it by not specifying all -lxx options with every file. Just the ones needed. Or you can leave it as it is no problem at all.

mox601
06-03-2007, 07:41 AM
thanks for the help, i can run the ./palazzo, now i will try cleaning unnecessary linkings.

memfr0b
06-03-2007, 08:07 AM
The messages aren't generated because some libs aren't used, but because you're using link flags during compilation. Compilation (transforming source code to binary code) and linking (combining various object files to a single binary or library) are two separate stages with different options.

-l flags tell the linker include referenced code from the mentioned library, which is only done during linking.

Simply remove $(LINKLIBS) from the "%.o: %.c" rule. Only the "palazzo" rule needs them, as it is the only rule that calls the linker stage.