Compiler Preprocessor Stringizing to Add Quotes
이전 댓글 표시
OK, carrying on w/ the idea of linking w/ GFORTRAN, I started with one function to see if could build the C binding. It works to build, up to a point.
The F90 source file is where the prototype is taken from the C syntax in the mex library documentation
#include "fintrf.h"
module MEXFUNCTIONS
interface
subroutine mexerrmsgidandtxt(errorID, errorMsg) bind(C,name=mexerrmsgidandtxt)
use iso_c_binding, only: c_char
character(kind=c_char) :: errorID(*), errorMsg(*)
end subroutine
end interface
end module
Compiling this and looking at the output of the preprocessor, the above goes thru the preprocessor step with no errors/warnings and produces
C:\GCC\bin\tmp> gfortran -E -Dm64 -DMATLAB_MEX_FILE -I C:\ML_R2020b\extern\include mexFunctionsModule.F90
# 1 "mexFunctionsModule.F90"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "mexFunctionsModule.F90"
# 1 "C:\\ML_R2020b\\extern\\include/fintrf.h" 1
# 9 "mexFunctionsModule.F90" 2
module MEXFUNCTIONS
interface
subroutine mexerrmsgidandtxt800(errorID, errorMsg) bind(C,name=mexerrmsgidandtxt800)
use iso_c_binding, only: c_char
character(kind=c_char) :: errorID(*), errorMsg(*)
end subroutine
end interface
end module
C:\GCC\bin\tmp>
where it can be observed the #define substitution of "mexerrmsgidandtxt800" for the source code string "mexerrmsgidandtxt".
Digging into the include file, it turns out the "800" suffix is one attached for the latest version and is set dynamically by some logic internal to the include file.
The above is fine excepting for and the reason for the Q?, the line
subroutine mexerrmsgidandtxt800(errorID, errorMsg) bind(C,name=mexerrmsgidandtxt800)
needs the entry name inside the bind() argument list to be a quoted string like
subroutine mexerrmsgidandtxt800(errorID, errorMsg) bind(C,name="mexerrmsgidandtxt800")
I have not been able to figure out a way to have the preprocessor insert the quotes around the entrypoint name automagically--anybody here know the preprocessor well enough to write a macro or whatever is needed? One could, of course, go back and fix the source file and boot the preprocessor, but that will take a fair amount of work.
I was familiar with the $CDEC pragmas that allowed for how to set the calling mechanisms and decorate names with CVF and is also available in the Intel compiler, but it doesn't appear the gfortran/gcc suite implements the range of options available there; all I've been able to find is that one can set STDCALL, but it has the side effect of appending "@bytes" to the name where "bytes" is the number of bytes on the call stack from the argument list.
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Call C++ from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!