我下載了this source code (.zip),並希望在我的Mac(OSX 10.11.2)上用XCode V7.2(7C68)進行編譯。我應該如何編譯這個C代碼?
我開始編制該文件fdist.c
與
gcc -o fdist2 -O fdist.c -lm
但它返回一個長系列的警告和錯誤(見下文)。看着這個文件,我發現它確實不像我習慣的那種代碼。通常情況下,函數返回的對象類型似乎未指定。
README_fdist2
沒有什麼幫助。有關於如何編譯代碼的指導原則,但第一行存在拼寫錯誤。
我該如何編譯這段代碼?
下面是錯誤和警告gcc -o fdist2 -O fdist.c -lm
返回
fdist2.c:42:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
main()
^
fdist2.c:117:3: warning: implicit declaration of function 'sim1' is invalid in C99
[-Wimplicit-function-declaration]
sim1(init,initot,rm,mu,freq_arr,val_arr,&noall);
^
fdist2.c:119:4: warning: implicit declaration of function 'my_thetacal' is invalid in C99
[-Wimplicit-function-declaration]
my_thetacal(freq_arr,noall,init,Subs,&h0,&h1,&fst);
^
fdist2.c:136:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
sim1(init,initot,rm,mu,freq_arr,val_arr,noall)
^
fdist2.c:222:3: warning: implicit declaration of function 'dfill' is invalid in C99
[-Wimplicit-function-declaration]
dfill();
^
fdist2.c:234:4: warning: implicit declaration of function 'cnode' is invalid in C99
[-Wimplicit-function-declaration]
cnode(k);
^
fdist2.c:237:8: warning: implicit declaration of function 'mnode' is invalid in C99
[-Wimplicit-function-declaration]
else mnode(k);
^
fdist2.c:252:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
fdist2.c:254:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
thetacal(gen,noall,sample_size,no_of_samples,het0,het1,fst)
^
fdist2.c:293:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
fdist2.c:301:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
dfill()
^
fdist2.c:312:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
fdist2.c:315:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
cnode(sp)
^
fdist2.c:349:2: error: non-void function 'cnode' should return a value [-Wreturn-type]
return;
^
fdist2.c:353:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
mnode(sp)
^
fdist2.c:464:2: error: non-void function 'mnode' should return a value [-Wreturn-type]
return;
^
fdist2.c:489:10: warning: implicit declaration of function 'poidev' is invalid in C99
[-Wimplicit-function-declaration]
mutno = poidev(time*mu);
^
fdist2.c:491:12: warning: implicit declaration of function 'addmut' is invalid in C99
[-Wimplicit-function-declaration]
p->dna = addmut(p->dna);
^
fdist2.c:676:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
mom(x,n,x1,x2,x3,x4,min,max)
^
fdist2.c:707:2: error: non-void function 'mom' should return a value [-Wreturn-type]
return;
^
fdist2.c:761:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
my_thetacal(gen,noall,sample_size,no_of_samples,het0,het1,fst)
^
18 warnings and 3 errors generated.
謝謝您的回答。我試過'-std = c89'和'-std = c90',但在兩種情況下仍然失敗。 –
你仍然得到所有這些警告?另一個選項是'-std = gnu89'。如果沒有,你可以爲函數做聲明。這就是你需要真正解決它們的問題。 –
我沒有得到相同的警告,但我仍然得到相同的錯誤。與'-std = gnu89'一樣。所以我想,我只需要自己編輯代碼的合成代碼,對吧? –