Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22077

Incompatible implicit declaration and other compile problems in C

$
0
0

I am new to fortran and I have to run some files. I installed MinGW and followed instructions from youtube video https://www.youtube.com/watch?v=xuQL_BZydS0 for Windows 10 I added the enviroment path.

I opened the command prompt went to the folder I have the files and typed the command gfortran -O3 reader.f iotools.c -o reader.x I got some errors which I wrote above, and I tried to fix them by adding int infront of the functions it mentioned and #include <stdlib.h> but I am not sure if I did correct. The file iotools.c, I attached is as given

C:\Users\user\Desktop\Ex>gfortran -O3 reader.f iotools.c -o reader.x
iotools.c: In function 'iwritecfw_':
iotools.c:85:11: warning: implicit declaration of function 'exit' [-Wimplicit-function-declaration]
      exit(1);}
      ^~~~
iotools.c:85:11: warning: incompatible implicit declaration of built-in function 'exit'
iotools.c:85:11: note: include '<stdlib.h>' or provide a declaration of 'exit'
iotools.c: In function 'idpwritecfw_':
iotools.c:98:11: warning: incompatible implicit declaration of built-in function 'exit'      exit(1);}
      ^~~~
iotools.c:98:11: note: include '<stdlib.h>' or provide a declaration of 'exit'
iotools.c: In function 'ireadcfr_':
iotools.c:134:11: warning: incompatible implicit declaration of built-in function 'exit'      exit(1);}
      ^~~~
iotools.c:134:11: note: include '<stdlib.h>' or provide a declaration of 'exit'
iotools.c: In function 'idpreadcfr_':
iotools.c:147:11: warning: incompatible implicit declaration of built-in function 'exit'      exit(1);}
      ^~~~
iotools.c:147:11: note: include '<stdlib.h>' or provide a declaration of 'exit'
iotools.c: At top level:
iotools.c:174:1: warning: return type defaults to 'int' [-Wimplicit-int]
 idumpc_(vector,nbytes)
 ^~~~~~~
iotools.c:184:1: warning: return type defaults to 'int' [-Wimplicit-int]
 idpdumpc_(vector,nbytes)
 ^~~~~~~~~
iotools.c:195:1: warning: return type defaults to 'int' [-Wimplicit-int]
 ireadc_(vector,nbytes)
 ^~~~~~~
iotools.c:205:1: warning: return type defaults to 'int' [-Wimplicit-int]
 idpreadc_(vector,nbytes)
 ^~~~~~~~~

initial file of iotools.c

/* iotools.c utilities, to read and write binary C from FORTRAN */



#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#ifndef O_BINARY
#define O_BINARY 0
#endif 

FILE *fw ;  /* pointers to the files used for writing   */
FILE *fr ;  /*                  and reading             */


/******* OPENING AND CLOSING ROUTINES ******************************************/

void openfilew_(namef)
/* opens for binary writting a file with fortran name namef. First translate the 
fortran string namef to the C string namec . 
>From fortran it is called as call openfilew(namef)  */
 char *namef;
{
 char namec[80];
 int i;
 strncpy(namec,namef,80);
/* character strings in fortran are filled with empty spaces. In C, they 
should finish with \0 . Thus, translate */
 i=0;
 for ( ;namec[i] != '' ; ++i){}
 namec[i]='\0';
 fw=fopen(namec,"wb");       /* this is the actual file opening */
 if (fw == NULL) {fprintf(stderr,"Error opening file %s \n",namec);  } 
 return ;
}


void openfiler_(namef)
/* opens for binary reading a file with fortran name namef. First translate the 
fortran string namef to the C string namec . 
>From fortran it is called as call openfiler(namef)   */
 char *namef;
{
 char namec[80];
 int i;
 strncpy(namec,namef,80);
/* character strings in fortran are filled with empty spaces. In C, they 
should finish with \0  */ 
 i=0;
 for ( ;namec[i] != '' ; ++i){}
 namec[i]='\0';
 fr=fopen(namec,"rb");     /* this is the actual file opening */
 if (fr == NULL) {fprintf(stderr,"Error opening file %s \n",namec);  } 
 return ;}


void closefilew_(void)
/* close the writing file opened by openfilew. From fortran 
it is called as call closefilew()    */
{fclose(fw);
return;
}

void closefiler_(void)
/* close the reading file opened by openfiler. From fortran 
it is called as call closefiler()    */
{fclose(fr);
return;
}

/******* WRITING ROUTINES ******************************************/

int iwritecfw_(vector,nelements)
/* writes in binary C to the file fw opened for writing a float 
    vector of nelements. It returns the number of elements (nelements) written. 
>From fortran it is called as icontrol=iwritecfw(vector,nelements)  , with 
vector a single precision float  */
 float *vector;
 int *nelements;
{
if (fw == NULL){
          fprintf(stderr,"C-binary file is not open to read\n");
          exit(1);}
 return fwrite(vector,4,*nelements,fw);
}


int idpwritecfw_(vector,nelements)
/* idem, but vector is a double precision float
>From fortran it is called as icontrol=idpwritecfw(vector,nelements)  */
 double *vector;
 int *nelements;
{
if (fw == NULL){
          fprintf(stderr,"C-binary file is not open to read\n");
          exit(1);}
 return fwrite(vector,8,*nelements,fw);
}


int iwritecstdout_(vector,nelements)
/* writes in binary C to stdout a float 
    vector of nelements. It returns the number of elements (nelements) written. 
>From fortran it is called as icontrol=iwritecstdout(vector,nelements). Under cygwin, first
fix the stdout stream to binary by using fixstd() */
 float *vector;
 int *nelements;
{ return fwrite(vector,4,*nelements,stdout); }


int idpwritecstdout_(vector,nelements)
/* idem, but vector is a double precision float
>From fortran it is called as icontrol=idpwritecstdout(vector,nelements). Under cygwin, first
fix the stdout stream to binary by using fixstd() */
 double *vector;
 int *nelements;
{ return fwrite(vector,8,*nelements,stdout); }


/******* READING ROUTINES *******************************************/

int ireadcfr_(vector,nelements)
/* reads in binary C from the file fr opened for reading a float 
    vector of nelements. It returns the number of elements (nelements) read. 
>From fortran it is called as icontrol=ireadcfr(vector,nelements) , with 
vector a single precision float.   */
 float *vector;
 int *nelements;
{
 if (fr == NULL){
          fprintf(stderr,"C-binary file is not open to read\n");
          exit(1);}
 return fread(vector,4,*nelements,fr);
}


int idpreadcfr_(vector,nelements)
/* idem, but vector is a double precision float. 
>From fortran it is called as icontrol=idpreadcfr(vector,nelements).   */
 double *vector;
 int *nelements;
{
 if (fr == NULL){
          fprintf(stderr,"C-binary file is not open to read\n");
          exit(1);}
 return fread(vector,8,*nelements,fr);
}


int ireadcstdin_(vector,nelements)
/* reads in binary C from stdin a float 
    vector of nelements. It returns the number of elements (nelements) read. 
>From fortran it is called as icontrol=ireadcstdin(vector,nelements). Under cygwin, first
fix the stdin stream to binary by using fixstd() */
 float *vector;
 int *nelements;
{ return fread(vector,4,*nelements,stdin); }


int idpreadcstdin_(vector,nelements)
/* idem, but vector is a double precision float.  
>From fortran it is called as icontrol=idpreadcstdin(vector,nelements). Under cygwin, first
fix the stdin stream to binary by using fixstd() */
 double *vector;
 int *nelements;
{ return fread(vector,8,*nelements,stdin); }


/******* The following are non-ANSI C functions   *****************/


idumpc_(vector,nbytes)
/* the same as iwritecstdout , but using write instead of fwrite. nbytes is the 
number of bytes, i.e.  4*nelements. It returns the number of bytes written.
>From fortran it is called as icontrol=idumpc(vector,nbytes). 
Under cygwin, first fix the stdout stream to binary by using fixstd()  */
  float *vector;
  int *nbytes; 
  {return( write(1,vector,*nbytes) );}   
/* 0 is stdin, 1 is stdout, 2 is stderr */

idpdumpc_(vector,nbytes)
/* idem, but vector is double precision. nbytes is the 
number of bytes, i.e.  8*nelements. It returns the number of bytes written.
>From fortran it is called as icontrol=idpdumpc(vector,nbytes). 
Under cygwin, first fix the stdout stream to binary by using fixstd()  */
  double *vector;
  int *nbytes; 
  {return( write(1,vector,*nbytes) );}   
/* 0 is stdin, 1 is stdout, 2 is stderr */


ireadc_(vector,nbytes)
/* the same as ireadcstdin , but using read instead of fread. nbytes is the 
number of bytes, i.e.  4*nelements. It returns the number of bytes read. 
>From fortran it is called as icontrol=ireadc(vector,nbytes).
Under cygwin, first fix the stdin stream to binary by using fixstd()   */
  float *vector;
  int *nbytes;
  {return( read(0,vector,*nbytes) );}
/* 0 is stdin, 1 is stdout, 2 is stderr */

idpreadc_(vector,nbytes)
/* idem, but vector is double precision. nbytes is the 
number of bytes, i.e.  8*nelements. It returns the number of bytes read. 
>From fortran it is called as icontrol=idpreadc(vector,nbytes).
Under cygwin, first fix the stdin stream to binary by using fixstd()   */
  double *vector;
  int *nbytes;
  {return( read(0,vector,*nbytes) );}
/* 0 is stdin, 1 is stdout, 2 is stderr */


/* void fixstd_(void)
use this only under cygwin (unix-like environment for windows) and only before 
using iwritecstdout and/or ireadcstdin (or ireadc or idumpc) redirected to local files. 
It changes the default mode from text to binary. 
It will do nothing under other circunstances (but O_BINARY will be undefined in most 
non-cygwin environments, so comment out this function when compiling there) .
{ setmode(1,O_BINARY);
 setmode(0,O_BINARY);   }  
 0 is stdin, 1 is stdout, 2 is stderr */

Viewing all articles
Browse latest Browse all 22077

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>