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

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

markusda
Beginner
337 Views

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.

0 Kudos
3 Replies
markusda
Beginner
337 Views

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? 

0 Kudos
markusda
Beginner
337 Views

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

0 Kudos
IanH
Honored Contributor II
337 Views

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)..

0 Kudos
Reply