c - 程序将不再找到 math.h

标签 c linux linker libm

过了很长时间,我下载了一个我共同开发的程序,并试图在我的 Ubuntu Linux 12.04 上重新编译它,但它似乎找不到 math.h 了。这可能是因为 gcc 最近发生了一些变化,但我无法确定是 src/Makefile.am 有问题还是缺少依赖:

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

我得到: [...]

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

有这些库是因为这个简单的例子运行得非常好:

$ 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;
}

有什么想法吗?

最佳答案

库需要放在编译器命令的末尾,就像您在简单示例中所做的那样:

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 Link Options :

-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.

关于c - 程序将不再找到 math.h,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11397920/

相关文章:

c - 如何使struct指针指向静态char数组

使用 2 的补码将 int 转换为二进制字符串再转换为 int

c - 如何在 header 中构造函数,在源代码中定义

linux - 如何将输出通过管道传输到 stdout 并传输到 docker 中的另一个进程

node.js - 错误 : Failed to launch the browser process! Whatsapp web js | Azure 门户 Linux puppeteer 师

c++ - 如何修复错误 : g++. exe:无法使用 -c 或 -S 指定 -o 以及多次编译

linux - Linux下如何同时为用户创建hdfs目录?

c++ - Boost::FileSystem 链接问题

c++ - 我的模板类的多个定义

c++ - 修改dll导出(符号表)。我想混淆函数名称