2012-07-09 45 views
1

經過很長時間,我下載了一個我共同開發的程序,並試圖在我的Ubuntu Linux 12.04上重新編譯它,但似乎它找不到math.h了。這可能是因爲事情已經在gcc最近改變了,但我不能弄清楚,如果這件事情錯在src/Makefile.am或丟失的依賴:程序不會再找到math.h

下載從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; 
} 

任何想法?

+1

它找到標題,但不是庫,或至少不是它正在尋找的符號。如果您在測試文件上嘗試這兩個命令會怎麼樣? 'gcc -DNDEBUG -O3 -W -Wall -ansi -pedantic -lm -o test.o -c test.c'和'gcc -DNDEBUG -O3 -W -Wall -ansi -pedantic -lm -o test test.o '?運行'make'時可能環境變量不正確? – mkb 2012-07-09 15:16:48

+0

我在製作過程中遇到了完全相同的錯誤。 – flak37 2012-07-09 15:17:15

+0

@mkb第二個命令有效,第一個失敗,出現此錯誤:'警告:ISO C90不支持'%lf'gnu_printf格式[-Wformat]' – 719016 2012-07-09 15:23:03

回答

3

圖書館需要去在編譯器命令結束時,當你在簡單的例子有:

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

將'-lm -o variscan'移動到行尾,但我不知道如何在'src/Makefile.am'中更改它以使其自動執行。 – 719016 2012-07-09 16:03:03

1

好像這個簡單的變化就足夠了在Makefile.am

+variscan_LDADD = -lm 
-variscan_LDFLAGS = -lm 
+0

庫不屬於'LDFLAGS'。它們屬於一個單獨的變量,它將在鏈接器命令行的**結尾**,通常稱爲LIBS。我忘記了automake更喜歡哪個名字。 – 2012-07-09 18:09:48