how to using cpp calling PGI fortran

I want to using cpp calling PGI fortran in vs2005 IDE.
the test example is get from PGI fortran user’s guide. i am not succeed.
would you like to provide an example if you can? thanks!

Hi,

There are examples in PVF user guide. Chapter 11: Inter-language Calling have examples of Fortran Calling C or C++ and vice versa.

Hongyon

yes, I try do it. But i am not successful. would you like help me? I can email the project to you. thanks!

cpp code:
#include
using namespace std;
extern “C" {extern void forts_(char *,char *,int *,int *,float *,double *,short *); }
void main ()
{
char bool1, letter1;
int numint1, numint2;
float numfloat1;
double numdoub1;
short numshor1;

forts_(&bool1,&letter1,&numint1,&numint2,&numfloat1,&numdoub1,&numshor1);
cout << " bool1 = ";
bool1?cout << "TRUE ":cout << "FALSE "; cout <<endl;
cout << " letter1 = " << letter1 <<endl;
cout << " numint1 = " << numint1 <<endl;
cout << " numint2 = " << numint2 <<endl;
cout << " numfloat1 = " << numfloat1 <<endl;
cout << " numdoub1 = " << numdoub1 <<endl;
cout << " numshor1 = " << numshor1 <<endl;
}
fortran code
subroutine forts(bool1, letter1, numint1,numint2, numfloat1, numdoub1, numshor1)
logical1 bool1
character letter1
integer numint1, numint2
double precision numdoub1
real numfloat1
integer
2 numshor1

bool1 = .true. ; letter1 = “v” ; numint1 = 11; numint2 = -44
numdoub1 = 902 ; numfloat1 = 39.6 ; numshor1 = 299

return
end

by the way, if i use the cpp code name *.c, when compile the code, the include iostream is error (based on vs2005)[/code]

Hi,

What target do you want to compile on, linux, win64, win32?

If windows, what compiler do you use to compile c++ program? pgcpp or cl? Are you doing this in PVF?

Hongyon

the target is win32 and the compiler is microsoft visual studio 2005. I wish I can do it in IDE. thanks!

Hi,

If possible I would use pgcc or pgcpp to compile and link both C/C++ and Fortran because it will make your life easier at link time as PGI drivers handle everything for you.

On win32, PGI’s default calling convention for Fortran is stdcall. You need to specify that in your C/C++ source.

For example in C,
#define ccsm CCSM
extern void __stdcall CCSM(int* a);

void test(){
int a;
ccsm(&a);
}


If you decide to use cl to compile and link, you will have to make sure you link with all PGI runtime libraries.

We have PVF(PGI Visual Fortran) which incorporates PGI compilers and tools into Microsoft Visual Studio. Check it out at: http://www.pgroup.com/products/pvf.htm


Hongyon