Linking Math Library in GCC 4.6.1 (Ubuntu 11.10)

后端 未结 4 348
被撕碎了的回忆
被撕碎了的回忆 2021-01-22 01:24

I find a problem in the linking process of my application. I did not have the same with gcc 4.5. It tries to link math library with the following command.

gcc -W         


        
4条回答
  •  礼貌的吻别
    2021-01-22 01:32

    I've had the same problem with gcc 4.6.1, even with only one library. This doesn't work:

    $ gcc -lm eg.o -o eg
    eg.o: In function `foo':
    /home/nick/tmp/eg.c:5: undefined reference to `sqrt'
    collect2: ld returned 1 exit status
    

    But this does:

    $ gcc eg.o -o eg -lm
    

    I hit this because I was using "LDFLAGS=-lm" in my Makefile. Works fine if you use "LDLIBS=-lm" instead.

提交回复
热议问题