Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

Call fortran DLL from C++

rezaei
Beginner
430 Views

I have problem with calling Fortran Dll from visual C++. The C++ and FORTRAN codes that I write are:

#include

#include

extern "C" __declspec(dllimport) void _stdcall DLL_ROUT (

int *INT_ARG,

char *STR_IN,

int STR_IN_LEN,

char *STR_OUT,

int STR_OUT_LEN);

void main (int argc, char *argv[])

{

char instring[40];

char outstring[40];

int intarg;

strcpy(instring,"Testing...");

intarg = 123;

DLL_ROUT(&intarg,instring,strlen(instring),outstring,40);

printf("%s\n",outstring);

}

SUBROUTINE DLL_ROUT (INT_ARG, STR_IN, STR_OUT)

IMPLICIT NONE

!DEC$ ATTRIBUTES DLLEXPORT :: DLL_ROUT

INTEGER INT_ARG

CHARACTER*(*) STR_IN, STR_OUT

CHARACTER*5 INT_STR

WRITE (INT_STR,'(I5.5)')INT_ARG

STR_OUT = STR_IN // INT_STR // CHAR(0)

RETURN

END

The error of program is such as this "error LNK2019: unresolved external symbol __imp__DLL_ROUT@20 referenced in function _main cmain.obj"

Sincerely yours

Behnam Rezaei

0 Kudos
4 Replies
af123_af007
Beginner
430 Views
Quoting - rezaei

I have problem with calling Fortran Dll from visual C++. The C++ and FORTRAN codes that I write are:

#include

#include

extern "C" __declspec(dllimport) void _stdcall DLL_ROUT (

int *INT_ARG,

char *STR_IN,

int STR_IN_LEN,

char *STR_OUT,

int STR_OUT_LEN);

void main (int argc, char *argv[])

{

char instring[40];

char outstring[40];

int intarg;

strcpy(instring,"Testing...");

intarg = 123;

DLL_ROUT(&intarg,instring,strlen(instring),outstring,40);

printf("%sn",outstring);

}

SUBROUTINE DLL_ROUT (INT_ARG, STR_IN, STR_OUT)

IMPLICIT NONE

!DEC$ ATTRIBUTES DLLEXPORT :: DLL_ROUT

INTEGER INT_ARG

CHARACTER*(*) STR_IN, STR_OUT

CHARACTER*5 INT_STR

WRITE (INT_STR,'(I5.5)')INT_ARG

STR_OUT = STR_IN // INT_STR // CHAR(0)

RETURN

END

The error of program is such as this "error LNK2019: unresolved external symbol __imp__DLL_ROUT@20 referenced in function _main cmain.obj"

Sincerely yours

Behnam Rezaei

In my case I call every Fortran Subroutine withDLL_ROUT_. But I dont know if that solves your problem.
0 Kudos
rezaei
Beginner
430 Views

If it is possible for you put your source code in C++ and FORTRAN (that is run successfully) in this forum, please.

Thank you.

0 Kudos
JenniferJ
Moderator
430 Views
what are your C++ compile and link options?
0 Kudos
rezaei
Beginner
430 Views
My C++ compiler is Visual studio 2005 and FORTRAN compiler is Compaq Visual Fortran.

0 Kudos
Reply