Undefined reference to exp on Ubuntu (including math.h and link to -lm)

I'm having trouble trying to compile a program that uses the exp function on Ubuntu. I get this error from gcc:

selied@Apolo :~/Dropbox/practicas UAM/Neuro/practica3$ make gcc -lm -o retropropagacion retropropagacion.o retropropagacion.o: In function `main': /home/selied/Dropbox/practicas UAM/Neuro/practica3/retropropagacion.c:177: undefined reference to `exp' /home/selied/Dropbox/practicas UAM/Neuro/practica3/retropropagacion.c:186: undefined reference to `exp' /home/selied/Dropbox/practicas UAM/Neuro/practica3/retropropagacion.c:297: undefined reference to `exp' /home/selied/Dropbox/practicas UAM/Neuro/practica3/retropropagacion.c:306: undefined reference to `exp' collect2: ld devolviΓ³ el estado de salida 1 make: *** [retropropagacion] Error 1 

Here I will show you my makefile.

 CC = gcc LDLAGS = -lm CFLAGS = -Wall -g EXE = retropropagacion normalizar OBJ = INC = compile : $(EXE) clean : @echo Borrando archivos temporales... rm -f *~ *.o core $(EXE) help : @echo backpropagation : ./retropropagacion entrada.txt 0 0 salida.txt and : ./retropropagacion and.dat 0 0 salida_and.txt $(EXE) : % : %.o $(OBJ) $(CC) $(LDLAGS) -o $@ $@.o $(OBJ) %.o : %.c $(INC) $(CC) $(CFLAGS) -c $< 

I also include the top of my header file and it works on another computer.

Do you know what is going on?

+4
source share
2 answers
 $(CC) $(LDLAGS) -o $@ $@.o $(OBJ) 

it should be

 $(CC) -o $@ $@.o $(OBJ) $(LDLAGS) 

Is it possible to specify the -l flags before the object files will depend on the version of GCC.

+9
source

Nothing. For further interest in this subject or struggle too long, also a line

 LDLAGS = -lm 

should be written as

 LDLIBS = -lm 

since LDLIBS are placed after the object files, unlike LDFLAGS , which ends before them in the default template, as documentation hints.

+1
source

Source: https://habr.com/ru/post/1386140/


All Articles