2016-07-19 2 views
0

기본적으로 작동하는 프로그램을 변경하는 데 문제가 있습니다. 오래 전에 제 친구 (지금 먼 친구)로부터 많은 프로그램을 얻었습니다. 그리고 그들은 잘 작동해야합니다. 그러나 아마도 작업 코드를 컴파일하려고하면 오류가 발생합니다.오류 : 'fmin'에 대한 충돌 유형

프로그램은 Numeric recipes의 라이브러리 nr.h와 nrutil.h를 사용하며 모두 fmin 선언을 포함합니다. '

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)); 

원래 프로그래머가 같은 프로그램을 실행할 수했지만, 난 할 수 있습니다 내가 오류 메시지를 얻을 프로그램을 컴파일 할 때 이제

#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); 
} 

:

코드는 그것을 컴파일하십시오. 그 원인은 무엇일까요? Cygwin에서 컴파일하려고합니다.

미리 감사드립니다.

+0

비슷한 문제 (기능 이름 만 다름) [여기 ** ** 찾을 수 있습니다 **] (https://stackoverflow.com/questions/33572503/conflicting-types-error). – WhozCraig

답변

1

fmin은 헤더 math.h (인수는 double)에서 미리 정의 된 함수입니다.

"recipes/nr.h"이라는 헤더 파일에 사용자 정의 함수가 있는데이 함수는 fmin이라는 함수가 있지만 서명이 다릅니다.

따라서 컴파일러에서 오류가 발생했습니다. 헤더 파일에서 함수 이름을 변경하면 오류가 해결됩니다.