Include a Fortran dll in C by The Visual Studio Command Line Compiler

Include a Fortran dll in C by The Visual Studio Command Line Compiler

Hello,

i need to distribute a fortran dll which is going to be called from a native c program. It is compiled by The Command line compiler of Visual Studio Version 15.

Linking a Fortran dll in a "normal" Visual Studio c-Projekt works fine.

But when I try to link the *.lib in the Command line compiler, I always get error LNK1120: 1 unresolved symbols.

http://social.msdn.microsoft.com/Forums/vstudio/en-US/00ff8f56-2545-492a-bc1b-612df1553043/native-c-code

I use the Fortran Compiler Intel Visual Fortran Composer XE 2013.

Here is what I have: 

Fortran function:

DOUBLE PRECISION FUNCTION ADDITION(A,B)

!DEC$ ATTRIBUTES DLLEXPORT:: ADDITION

USE ISO_C_BINDING

REAL (KIND = C_DOUBLE) :: A,B

ADDITION = A+B

END

The c program test.c:

#include <windows.h>
#include <stdio.h>
#include <string.h>

extern double ADDITION(double a,double b);

int main ()
{

char enter = 0;

double result = ADDITION(1, 2);

printf("The result is: %f\n", result);

printf("Press enter to continue\n");

while (enter != '\r' && enter != '\n') { enter = getchar(); }
printf("Thank you for pressing enter\n");

return 0;
}

The command lines for the Compiler:

cl test.c fortran_code.lib

The fortran_code.dll and the fortran_code.lib are in the same folder than test.c. So that should be ok.

Any ideas what I made wrong? Thank you.

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hello,

I replaced the c-Function ADDITION with _ADDITTION

Now i get the following error:

/out:test.exe

test.obj

fortran_code.lib

fortran_code.lib(fortran_code.dll): fatal error LNK1112: Modul Computertype "x86" conflicts with the target type "x64"

Switching the MIDL-Switches for Target Environment from x86 to x64 in my fortran project don't work either. Any ideas? 

********* ALREADY SOLVED THE PROBLEM :) Thanks anyway

Perhaps this was your solution, but you needed the BIND(C, NAME='ADDITION') suffix in the FUNCTION statement in the fortran.  The binding label given by the NAME specifier needs to match (case sensitive) the name you use for the fortran procedure in the C code (no need for additional leading or trailing underscores, etc)..

Leave a Comment

Please sign in to add a comment. Not a member? Join today