Reputation: 1305
I've been trying to compile my code and it doesn't want to work.
It gives me a message error that the reference is undefine.
I've used the math.h include in all my modules and my main file :
#include <math.h>
Here's the bash screen output :
bash-4.1$ make
gcc -W -Wall -lm -g -c -o imagePGM.o imagePGM.c
gcc tp2.o imagePGM.o -o tp2
imagePGM.o: In function `imageContraste':
imagePGM.c:(.text+0x1067): undefined reference to `floor'
imagePGM.c:(.text+0x10c1): undefined reference to `ceil'
imagePGM.c:(.text+0x1103): undefined reference to `floor'
imagePGM.o: In function `imageRatio':
imagePGM.c:(.text+0x1371): undefined reference to `floor'
imagePGM.c:(.text+0x13aa): undefined reference to `ceil'
imagePGM.c:(.text+0x13ce): undefined reference to `floor'
collect2: erreur: ld a retourné 1 code d'état d'exécution
make: *** [tp2] Erreur 1
bash-4.1$
I've used the "-lm" argument with the gcc.
Here's my makefile :
# Variables predefinies
CC = gcc
CFLAGS = -W -Wall -lm -g
# Dependances
# Par defaut, make (sans arguments) ne se soucie que de la premiere dependance rencontree
# Aucune action par defaut ici, car gcc ne "sait" pas comment traiter ces dependances
# Dependances plus complexes : on ne peut melanger .c, .o et .h dans la meme dependance
tp2 : tp2.o imagePGM.o
tp2.o : tp2.c imagePGM.h
# $(CC) $(CFLAGS) -c tp2.c
imagePGM.o : imagePGM.c imagePGM.h
clean :
rm tp2 tp2.o imagePGM.o
Do i need to implement something else or do something specific ?
Upvotes: 0
Views: 1445
Reputation: 1305
I've reworked my makefile from this :
# Variables predefinies
CC = gcc
CFLAGS = -W -Wall -g
LIBS=-lm
# Dependances
# Par defaut, make (sans arguments) ne se soucie que de la premiere dependance rencontree
# Aucune action par defaut ici, car gcc ne "sait" pas comment traiter ces dependances
# Dependances plus complexes : on ne peut melanger .c, .o et .h dans la meme dependance
tp2 : tp2.o imagePGM.o
tp2.o : tp2.c imagePGM.h
# $(CC) $(CFLAGS) -c tp2.c
imagePGM.o : imagePGM.c imagePGM.h
clean :
rm tp2 tp2.o imagePGM.o
To this :
CC=gcc
CFLAGS= -lm
DEPS = imagePGM.h
OBJ = imagePGM.o tp2.o
%.o: %.c $(DEPS)
$(CC) -W -Wall -c -o $@ $< $(CFLAGS)
tp2: $(OBJ)
gcc -W -Wall -o $@ $^ $(CFLAGS)
The flags are linked at the end
Upvotes: 1