Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Mixed language problem

rrimmer
Beginner
924 Views
I am using an evaluation license and am very new to Fortran. I am trying to complie a large Fortran program to use in Mathematica via MathLink so I need to be able to access the Fortran code from C. I can build a DLL file but cannot get it to link. Here is the error:

1>Linking...

1>mkspline.obj : error LNK2001: unresolved external symbol _R8MKSPLINE@36

1>C:MathLinkPSplineMLReleasePSplineML.exe : fatal error LNK1120: 1 unresolved externals

Here is how the Fortran file is set up:

subroutine r8mkspline(x,nx,fspl,ibcxmin,bcxmin,ibcxmax,bcxmax,

>ilinx,ier)

!DEC$ ATTRIBUTES DLLEXPORT :: R8MKSPLINE

and reading the .lib file with WordPad it looks like this at the end:

�_R8MKSPLINE�pspline.dll�

I am trying to reference it in C like this:

void _stdcall R8MKSPLINE(double *x, int *nx, double *fspl, int *ibcxmin, double *bcxmin, int *ibcxmax, double *bcxmax, int *ilinx, int *ier);

What else do I need to do. I feel that I am almost there this is the last error left, of course, it will probably be a miracle if it works in MathLink

Bob Rimmer

P.S. I couldn't seem to make it work as a static library, probably because the program makes a lot of write calls to the console. I can eventually get rid of these, but I would like to see something work before I edit 163 files.

0 Kudos
4 Replies
Jugoslav_Dujic
Valued Contributor II
924 Views
In Intel Fortran, the default calling convention was changed from CVF's __stdcall to __cdecl. That means that you should change that on C side.

If you instead need __stdcall for compatibility with other stuff, you can specify it on Fortran side like:

!DEC$ATTRIBUTES DLLEXPORT, STDCALL, DECORATE, ALIAS: "R8MKSPLINE":: R8MKSPLINE

That will give you "_R8MKSPLINE@36" instead of "_R8MKSPLINE".

Tip: there are two better tools for the job than Notepad. One is dumpbin.exe, used from command line like:

dumpbin /exports dllname.dll > temp.txt

and

dumpbin /symbols libname.lib > temp.txt

that will give you list of exact dll's exports and list of library's routines in file temp.txt.

The other is Dependency Walker, with nice GUI interface.
0 Kudos
rrimmer
Beginner
924 Views
__cdecl worked fine
Bob Rimmer
0 Kudos
paolo_becchi
Beginner
924 Views
Dear all,
I'm working with a combined VB6 - F90 code using F90 dll connected to the VB6 interface and I have some problems related to the data exchange between Visual Basic and Fortran, especially using user data type.
Please consider, for example, a structured user data type as the following:
Type datacurve
vector1 (1 to n) as double
End type
0 Kudos
paolo_becchi
Beginner
924 Views
Dear all,
I'm working with a combined VB6 - F90 code using F90 dll connected to the VB6 interface and I have some problems related to the data exchange between Visual Basic and Fortran, especially using user data type.
Please consider, for example, a structured user data type as the following:
Type datacurve
vector1 (1 to n) as double
matrix (1 to m, 1 to p) as single
....
End type
I have no problem if I have to exchange this kind of data between VB6 and F90 and back especially if the data type is already dimensioned.
But if I would like to read the data from a file using a F90 dll, I should have to allocate the datatype in F90 dll code pass it back to VB6, but I have problems related to the dimensions. So, at the moment, in order to avoid this problem, I call a pre-reading F90 subroutine that read the dimensional parameter (n, m, p and so on), comes back to the VB6 where the data type is dimensioned and then this data is exchanged again to the F90 dll code where the file is read and the user data type variables is stored.
Has somebody a better solution for this kind of problems.
Thank you very much for your contributions
0 Kudos
Reply