2016-07-19 104 views
0

我嘗試更改基本可用的程序時遇到問題。前段時間我從一個(現在很遠的)朋友那裏得到了一堆程序,他們應該工作的很好。但是,當我嘗試編譯大概工作的代碼時,我得到一個錯誤。錯誤:'fmin'的衝突類型

這些程序使用庫中的nr.h和nrutil.h庫,並且都包含聲明fmin

的代碼是:

#include <stdio.h> 
#include <math.h> 
#include "recipes/nrutil.h" 
#include "recipes/nr.h" 


float s(float t, float omega); 
float c(float t, float omega); 
void DFT(int dir, int N, float** mat); 

int main(int argc, char* argv[]) 
{ 
    int i,j; 
    int N=100; 
    float** mat=matrix(1,2,0,N); 
    float tmp; 

    for (i=0;i<=N;i++){ 
     tmp=s((1.0*i)/N,1.0); 
     if (tmp>=0.5) mat[1][i]=0.5; 
     else if (tmp<=0.5) mat[1][i]=-0.5; 
     else mat[1][i]=tmp; 
     mat[2][i]=0.0; 
    } 

    DFT(1,N,mat); 
    DFT(-1,N,mat); 
    FILE* fout=fopen("test.dat","w+"); 
/* 
    for (i=0;i<=N;i++) 
     fprintf(fout,"%d %0.16e %0.16e %0.16e\n",i 
                         ,mat[1][i] 
                         ,mat[2][i] 
                         ,s((1.0*i)/N,8.5)-mat[1][i]); 
*/ 

    for (i=0;i<=N;i++) 
     fprintf(fout,"%e %0.16e %0.16e %0.16e %d %0.16e\n",(i-N/2)*1.0/N 
                              ,mat[1][i] 
                              ,mat[2][i] 
                              ,sqrt(SQR(mat[1][i])+SQR(mat[2][i])) 
                              ,i 
                              ,s((1.0*i)/N,1.0)); 

    fclose(fout); 

    free_matrix(mat,1,2,0,N); 
    return (0); 
} 


float s(float t, float omega) 
{ 
    return (sin(2*M_PI*omega*t)); 
} 

float c(float t, float omega) 
{ 
    return (cos(2*M_PI*omega*t)); 
} 

void DFT(int dir, int N, float** mat) 
{ 
    int i,k; 
    float arg; 
    float cosarg,sinarg; 
    float** mat2=matrix(1,2,0,N); 

    if (dir==1){  
     for (i=-N/2;i<=N/2;i++){ 
      mat2[1][i+N/2]=0; 
      mat2[2][i+N/2]=0; 
      arg=-dir*2.0*M_PI*(float)i/(float)N; 
      for (k=0;k<N;k++){ 
       cosarg=cos(k*arg); 
       sinarg=sin(k*arg); 
       mat2[1][i+N/2]+=mat[1][k]*cosarg-mat[2][k]*sinarg; 
       mat2[2][i+N/2]+=mat[1][k]*sinarg+mat[2][k]*cosarg; 
      } 
     } 
     for (i=0;i<=N;i++){ 
      mat[1][i]=mat2[1][i]/(float)N; 
      mat[2][i]=mat2[2][i]/(float)N; 
     } 
    } 
    else{ 
     for (k=0;k<=N;k++){ 
      mat2[1][k]=0; 
      mat2[2][k]=0; 
      arg=-dir*2.0*M_PI*(float)k/(float)N; 
      for (i=-N/2;i<=N/2;i++){ 
       cosarg=cos(i*arg); 
       sinarg=sin(i*arg); 
       mat2[1][k]+=mat[1][i+N/2]*cosarg-mat[2][i+N/2]*sinarg; 
       mat2[2][k]+=mat[1][i+N/2]*sinarg+mat[2][i+N/2]*cosarg; 
      } 
     } 
     for (i=0;i<=N;i++){ 
      mat[1][i]=mat2[1][i]; 
      mat[2][i]=mat2[2][i]; 
     } 
    } 

    free_matrix(mat2,1,2,0,N); 
} 

現在,當我試圖編譯程序我得到一個錯誤信息:

In file included from nal01a.c:12:0: recipes/nr.h:188:7: error: 
conflicting types for ‘fmin’ float fmin(float x[]); 

In file included from nal01a.c:10:0: /usr/include/math.h:289:15: note: previous declaration of ‘fmin’ was 
here extern double fmin _PARAMS((double, double)); 

原來的程序員能夠運行同樣的程序,但我可以」編譯它。可能是什麼原因?我試圖用Cygwin編譯它。

非常感謝提前。

+0

類似的問題(只有函數名稱不同)[可以在這裏找到**](https://stackoverflow.com/questions/33572503/conflicting-types-error)。 – WhozCraig

回答

1

fmin是標頭math.h(其參數爲double)中的預定義函數。

發生了什麼是您的頭文件中有一個名爲"recipes/nr.h"的用戶定義函數,它具有名爲fmin的功能,但具有不同的簽名。

因此,編譯器發生錯誤。更改頭文件中函數的名稱,並且應該解決錯誤。