Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

C++ Code written in VS2010 is working in Linux but not in windows

Hi

I am working on VS2010 mixed-programing and use the Intel Compiler / VisualStudio (Intel Parallel 2015) to compile my project in VS 2010.

#include <conio.h>
#include <string.h>

//#define readfile readfile_

extern void readfile(char*, int*);

int main()
{
    int n, count;
    char Fname[9];
    char Name[10];

    strcpy(Fname,"AMIN.for");
    fprintf( stderr, "%s\n", Fname);

    readfile( Fname, &n , strlen (Fname));
    fprintf( stderr, "n = %d\n", n);
//  fprintf( stderr, "%s\n", Name);
    getch();
    return 0;
}
subroutine - Lib fortran:

      subroutine readfile( fname1, m )
      character fname1*(*)
      integer m
      integer iounit,i
      iounit=15
      write(*,*) fname1
c10   format (a9)
      open(iounit,file = fname1,action='read')
      read (iounit,*) m
c20    format (i10)
      write(*,*) m
      close(iounit)
      return 
      end subroutine

My program is compiling on Linux but not compiling in windows(VS) I don't know what happen exactly. Thanks 

0 Kudos
6 Replies
Highlighted

You might want to re-post

You might want to re-post your question on the Fortran forum.  Here is one post that I found which discusses calling Fortran from C: https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/515579

0 Kudos
Highlighted

Your screenshot is showing a

Your screenshot is showing a runtime error, not a compile time error.

When you run in the VS debugger, the default working directory is the Project directory of the executable (startup project). I suspect your data file is not located in the expected directory.

Also, it is not good practice to name your data file xxx.for
.for files are fixed format Fortran files.

Jim Dempsey

0 Kudos
Highlighted
Employee

Hi Muhammad,

Hi Muhammad,
I'll transfer this issue to the Fortran forum and you'll be supported by the engineers supporting that compiler towards resolution, fyi.
_Kittur

0 Kudos
Highlighted
Valued Contributor III

I didn't check closely the

I didn't check closely the code in this post, but it looks eerily familiar.  How's the issue at hand different from those in the previous threads by this OP for which RO and mecej4 have provided detailed assistance as well as working code?

https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/604747

https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/606064

0 Kudos
Highlighted
Valued Contributor II

Apart from that, the OP is

Apart from that, the OP is not using the correct invocation for the Fortran subroutine: in Fortran there is a hidden argument for character arguments which passes the length of the character variable to the subroutine. In absence of that argument, the routine may use any odd length.

I suggest that OP uses the ISO_C_BINDING feature to avoid this as well as the naming convention dependency - see the commented #define. Using that feature means that the interfacing between C and Fortran becomes platform-independent.

0 Kudos
Highlighted
Black Belt

I puzzled over this in the

I puzzled over this in the previous posting location.  OP tried to use the legacy appended string length argument, but there might be a data type mismatch between the std C strlen() function and the expected type for the Fortran implicit string length (would (int) cast paper over this?).  As Arjen said, upgrading the code to Fortran 2003 might avoid some confusion and permit the compiler to do some checking (as would more correct use of includes on the C side).

I don't know how conio.h could be expected to be portable across the range of platforms quoted here.

0 Kudos