- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I tried to call the c++ function from fortran main code.
finally, I found the sample MLP code from ...\Intel\Composer XE 2011 SP1\Samples\en_US\Fortran and i tried it.
but, I don't know how to set the Project setting for calling c++ function from fortran main program
So, I need the help for detailed procedure for mixing fortran and c++ in visual studio 2010 ,please
This is my fortran and c++ code(In the same sample project,.. my code working well but,not another project)
and I used same sample source code but, doesn't work in another new project.
---- Fmain.f90--------------------------------------------------
PROGRAM fmain2
IMPLICIT NONE
INTERFACE
SUBROUTINE ADD (a,b,RES) BIND(C,NAME='c_add')
USE,INTRINSIC :: ISO_C_BINDING ! Declares C kinds
INTEGER(c_int),INTENT(IN) :: a
INTEGER(c_int),INTENT(IN) :: b
INTEGER(c_int) :: RES
END SUBROUTINE ADD
SUBROUTINE SUB (a,b,RES) BIND(C,NAME='c_sub')
USE,INTRINSIC :: ISO_C_BINDING ! Declares C kinds
INTEGER(c_int),INTENT(IN) :: a
INTEGER(c_int),INTENT(IN) :: b
INTEGER(c_int) :: RES
END SUBROUTINE SUB
END INTERFACE
INTEGER :: a =2
INTEGER :: b =4
INTEGER :: RES
CALL ADD (a,b,RES)
WRITE(*,101) a,b,RES
101 FORMAT (1X,'IN FORTRAN a=',I3,' ,b= ',I3,' ,a+b= ', I4)
CALL SUB (a,b,RES)
WRITE(*,102) a,b,RES
102 FORMAT (1X,'IN FORTRAN a=',I3,' ,b= ',I3,' ,a-b= ', I4)
END PROGRAM
--- Csub.cpp ------------------------------------------------------------
#include <iostream>
using namespace std;
extern "C"
{
void c_add(int &a,int &b, int &RES)
{
RES = a+b;
cout << "In c_routine a ="<< a << " b =" << b << " a+b = " << RES << endl;
}
void c_sub(int &a,int &b, int &RES)
{
RES = a-b;
cout << "In c_routine a ="<< a << " b =" << b << " a-b = " << RES << endl;
}
}
----------------------------
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
By the way, in a version coming out this fall we are changing the library defaults when creating new VS projects to match C++, which will avoid this class of problem, though people will need to adjust...
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page