简体   繁体   English

在Ubuntu上对exp的未定义引用(包括math.h和使用-lm链接)

[英]Undefined reference to exp on Ubuntu (including math.h and linking with -lm)

I'm having some trouble trying to compile a program that uses exp function on Ubuntu. 我在尝试编译在Ubuntu上使用exp函数的程序时遇到了一些麻烦。 I get this error from gcc: 我从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 show you my makefile. 在这里,我向您展示我的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 $<

Also I have include at the top of my header file and it works on another computer. 此外,我已经包含在我的头文件的顶部,它可以在另一台计算机上运行。

Do you know what's happening? 你知道发生了什么吗?

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

should be 应该

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

Whether -l flags can be given before object files depends on the GCC version. 是否可以在目标文件取决于GCC版本之前给出-l标志。

Never mind. 没关系。 For further interested about this issue or struggling also too long, also line 对于这个问题还有进一步的兴趣还是挣扎也太久了,还行

LDLAGS  = -lm

should be written as 应该写成

LDLIBS = -lm

because LDLIBS are put after the object files, unlike the LDFLAGS , which ends in front of them in default make template, as documentation hints. 因为LDLIBS放在目标文件之后,不像LDFLAGS ,它在默认make模板的前面结束,正如文档提示的那样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM