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

How to obtain an executable file from a Fortran code with MATLAB mex

Jump to solution

Hi all,

I have a code containing MATLAB mex functions (enabling "calling" MATLAB files). It works well with the "debug" configuration, but I want to convert it into an executable file which allows me to use it without visual studio. I tried to change the configuration into "release" to get the executable file, but there are a lot of errors with the MATLAB mex part. It would be very helpful if anyone can tell me how to obtain this exe file.

Thank you!

The environment is: 64bit win10;  Intel parallel studio XE 2017fortran + Microsoft visual studio 2017.

The output information are:

1>------ Build started: Project: DNSQ_TEST, Configuration: Release x64 ------
1>Compiling with Intel(R) Visual Fortran Compiler 17.0.7.272 [Intel(R) 64]...
1>FCN.f90
1>C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\FCN.f90(1): warning #5117: Bad # preprocessor line
1>C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\FCN.f90(3): warning #5117: Bad # preprocessor line
1>C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\FCN.f90(5): warning #5117: Bad # preprocessor line
1>C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\FCN.f90(12): error #5082: Syntax error, found IDENTIFIER 'ENGOPEN' when expecting one of: => = . [ % ( :
1>C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\FCN.f90(13): error #5082: Syntax error, found IDENTIFIER 'MXGETPR' when expecting one of: => = . [ % ( :
1>C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\FCN.f90(14): error #5082: Syntax error, found IDENTIFIER 'EP' when expecting one of: => = . [ % ( :
1>C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\FCN.f90(18): error #5082: Syntax error, found IDENTIFIER 'I' when expecting one of: => = . [ % ( :
1>C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\FCN.f90(21): error #5082: Syntax error, found IDENTIFIER 'M' when expecting one of: => = . [ % ( :
1>C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\FCN.f90(16): error #6236: A specification statement cannot appear in the executable section.
1>C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\FCN.f90(17): error #6236: A specification statement cannot appear in the executable section.
1>C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\FCN.f90(22): error #6236: A specification statement cannot appear in the executable section.
1>C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\FCN.f90(23): error #6236: A specification statement cannot appear in the executable section.
1>C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\FCN.f90(12): error #6404: This name does not have a type, and must have an explicit type.   [ENGOPEN]
1>C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\FCN.f90(12): error #6304: This format specifier must be of type INTEGER.   [ENGOPEN]
1>C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\FCN.f90(12): error #6404: This name does not have a type, and must have an explicit type.   [ENGGETVARIABLE]
1>C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\FCN.f90(12): error #6404: This name does not have a type, and must have an explicit type.   [MXCREATEDOUBLEMATRIX]
1>C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\FCN.f90(14): error #6404: This name does not have a type, and must have an explicit type.   [EP]
1>C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\FCN.f90(14): error #6304: This format specifier must be of type INTEGER.   [EP]
1>C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\FCN.f90(14): error #6404: This name does not have a type, and must have an explicit type.  
1>C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\FCN.f90(14): error #6404: This name does not have a type, and must have an explicit type.  
1>C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\FCN.f90(21): error #6404: This name does not have a type, and must have an explicit type.  
1>C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\FCN.f90(21): error #6304: This format specifier must be of type INTEGER.  
1>C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\FCN.f90(21): error #6404: This name does not have a type, and must have an explicit type.   [NN]
1>C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\FCN.f90(34): error #6404: This name does not have a type, and must have an explicit type.   [MXGETPR]
1>C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\FCN.f90(39): error #6404: This name does not have a type, and must have an explicit type.   [STATUS]
1>C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\FCN.f90(39): error #6404: This name does not have a type, and must have an explicit type.   [ENGPUTVARIABLE]
1>C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\FCN.f90(58): error #6404: This name does not have a type, and must have an explicit type.   [ENGEVALSTRING]
1>compilation aborted for C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\FCN.f90 (code 1)
1>
1>Build log written to  "file://C:\Users\Rui\FORTRAN\DNSQ_TEST\DNSQ_TEST\x64\Release\BuildLog.htm"
1>DNSQ_TEST - 25 error(s), 3 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

The related subroutine is:

 

        SUBROUTINE FCN(N,X,FVEC,IFLAG)
        implicit none
        INTEGER N,IFLAG
        DOUBLE PRECISION X(N),FVEC(N)
      	mwPointer engOpen, engGetVariable, mxCreateDoubleMatrix  
     	mwPointer mxGetPr
     	mwPointer ep, G, T 
      	integer engPutVariable, engEvalString, engClose
      	integer temp, status
      	mwSize i
      	mwSize M, NN 
      	parameter(M=1) 
      	parameter(NN=9) 

      	ep = engOpen('matlabx')

      	if (ep .eq. 0) then
         write(6,*) 'Can''t start MATLAB engine'
         stop
      	endif

      	G = mxCreateDoubleMatrix(M, NN, 0) 
      	call mxCopyReal8ToPtr(X, mxGetPr(G), NN) 

      	status = engPutVariable(ep, 'G', G)

      	if (status .ne. 0) then 
         write(6,*) 'engPutVariable failed'
         stop
      	endif

       	if (engEvalString(ep, 'TEMP_test1') .ne. 0) then  

          write(6,*) 'engEvalString failed'
         stop
      	endif
      
      	T = engGetVariable(ep, 'T')
      	call mxCopyPtrToReal8(mxGetPr(T), FVEC, NN) 
      	call mxDestroyArray(G)
      	call mxDestroyArray(T)
       
    	end

 

 

0 Kudos

Accepted Solutions
Highlighted
35 Views

Are you missing some lines in your program?   The first three messages indicate that there are preprocessing lines (beginning with the character "#") but none show in the code you have posted.

"swpointer" is not a valid Fortran construct, nor is "swsize"

Let me guess that the missing lines look something like this:
#define swpointer integer(kind=int_ptr_kind())
#define swsize integer

If my guess is true, then you need to mark the RELEASE configuration use the preprocessor, as you did for the DEBUG configuration.

                      --Lorri

View solution in original post

0 Kudos
2 Replies
Highlighted
36 Views

Are you missing some lines in your program?   The first three messages indicate that there are preprocessing lines (beginning with the character "#") but none show in the code you have posted.

"swpointer" is not a valid Fortran construct, nor is "swsize"

Let me guess that the missing lines look something like this:
#define swpointer integer(kind=int_ptr_kind())
#define swsize integer

If my guess is true, then you need to mark the RELEASE configuration use the preprocessor, as you did for the DEBUG configuration.

                      --Lorri

View solution in original post

0 Kudos
Highlighted
Beginner
35 Views

Hi Lorri,

Thank you so much! Yes, I need to reset the preprocessor and other options, and then the problem can be solved.

Rui

Lorri Menard (Intel) wrote:

Are you missing some lines in your program?   The first three messages indicate that there are preprocessing lines (beginning with the character "#") but none show in the code you have posted.

"swpointer" is not a valid Fortran construct, nor is "swsize"

Let me guess that the missing lines look something like this:
#define swpointer integer(kind=int_ptr_kind())
#define swsize integer

If my guess is true, then you need to mark the RELEASE configuration use the preprocessor, as you did for the DEBUG configuration.

                      --Lorri

0 Kudos