简体   繁体   English

程序将找不到math.h了

[英]program won't find math.h anymore

After a long time, I downloaded a program I co-developed and tried to recompile it on my Ubuntu Linux 12.04, but it seems it does not find math.h anymore. 很长一段时间后,我下载了一个我共同开发的程序,并尝试在我的Ubuntu Linux 12.04上重新编译它,但它似乎找不到math.h了。 This may be because something has changed recently in gcc , but I can't figure out if it's something wrong in src/Makefile.am or a missing dependency: 这可能是因为gcc最近发生了一些变化,但我无法弄清楚src/Makefile.am是否存在错误或缺少依赖:

Download from http://www.ub.edu/softevol/variscan/ : http://www.ub.edu/softevol/variscan/下载:

tar xzf variscan-2.0.2.tar.gz 
cd variscan-2.0.2/
make distclean
sh ./autogen.sh
make

I get: [...] 我明白了:[...]

gcc -DNDEBUG -O3 -W -Wall -ansi -pedantic  -lm  -o variscan variscan.o statistics.o common.o linefile.o memalloc.o dlist.o errabort.o dystring.o intExp.o kxTok.o pop.o window.o free.o output.o readphylip.o readaxt.o readmga.o readmaf.o readhapmap.o readxmfa.o readmav.o ran1.o swcolumn.o swnet.o swpoly.o swref.o  
statistics.o: In function `calculate_Fu_and_Li_D':
statistics.c:(.text+0x497): undefined reference to `sqrt'
statistics.o: In function `calculate_Fu_and_Li_F':
statistics.c:(.text+0x569): undefined reference to `sqrt'
statistics.o: In function `calculate_Fu_and_Li_D_star':
statistics.c:(.text+0x63b): undefined reference to `sqrt'
statistics.o: In function `calculate_Fu_and_Li_F_star':
statistics.c:(.text+0x75c): undefined reference to `sqrt'
statistics.o: In function `calculate_Tajima_D':
statistics.c:(.text+0x85d): undefined reference to `sqrt'
statistics.o:statistics.c:(.text+0xcb1): more undefined references to `sqrt' follow
statistics.o: In function `calcRunMode21Stats':
statistics.c:(.text+0xe02): undefined reference to `log'
statistics.o: In function `correctedDivergence':
statistics.c:(.text+0xe5a): undefined reference to `log'
statistics.o: In function `calcRunMode22Stats':
statistics.c:(.text+0x104a): undefined reference to `sqrt'
statistics.o: In function `calculate_Fu_fs':
statistics.c:(.text+0x11a8): undefined reference to `fabsl'
statistics.c:(.text+0x11ca): undefined reference to `powl'
statistics.c:(.text+0x11f2): undefined reference to `logl'
statistics.o: In function `calculateStatistics':
statistics.c:(.text+0x13f2): undefined reference to `log'
collect2: ld returned 1 exit status
make[1]: *** [variscan] Error 1
make[1]: Leaving directory `/home/avilella/variscan/latest/variscan-2.0.2/src'
make: *** [all-recursive] Error 1

The libraries are there because this simple example works perfectly well: 这些库是因为这个简单的例子非常有效:

$ gcc test.c -o test -lm
$ cat test.c 
#include <stdio.h>
#include <math.h>
int main(void)
{
        double x = 0.5;
        double result = sqrt(x);
        printf("The hyperbolic cosine of %lf is %lf\n", x, result);
        return 0;
}

Any ideas? 有任何想法吗?

The library needs to go at the end of the compiler command, as you have in the simple example: 库需要在编译器命令的末尾进行,就像在简单示例中一样:

gcc -DNDEBUG -O3 -W -Wall -ansi -pedantic -o variscan variscan.o statistics.o common.o linefile.o memalloc.o dlist.o errabort.o dystring.o intExp.o kxTok.o pop.o window.o free.o output.o readphylip.o readaxt.o readmga.o readmaf.o readhapmap.o readxmfa.o readmav.o ran1.o swcolumn.o swnet.o swpoly.o swref.o statistics.o -lm gcc -DNDEBUG -O3 -W -Wall -ansi -pedantic -o variscan variscan.o statistics.o common.o linefile.o memalloc.o dlist.o errabort.o dystring.o intExp.o kxTok.o pop.o window .o free.o output.o readphylip.o readaxt.o readmga.o readmaf.o readhapmap.o readxmfa.o readmav.o ran1.o swcolumn.o swnet.o swpoly.o swref.o statistics.o -lm

From GCC Link Options : 来自GCC链接选项

-llibrary
-l library
    Search the library named library when linking. 
    (The second alternative with the library as a separate argument
    is only for POSIX compliance and is not recommended.)

    It makes a difference where in the command you write this option;
    the linker searches and processes libraries and object files in the
    order they are specified.
    Thus, `foo.o -lz bar.o' searches library `z' after file foo.o but
    before bar.o. If bar.o refers to functions in `z', those functions
    may not be loaded.

It seems like this simple change would suffice in Makefile.am : 看起来这个简单的改变就足够了Makefile.am

+variscan_LDADD = -lm
-variscan_LDFLAGS = -lm

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

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