combining c++ code module in fortran

Dear All,
I have the following problem:
main program in fortran and an external module in C++ (see below). I would like to build them together in pgi compiler. Any suggestion?
In gnu compiler I do:

gfortran -c -fcray-pointer -O3 main.for
g++ -c ext_lib.cpp
gfortran -o load_lib.exe *.o -lstdc++

Barak


Fortran code:

PROGRAM load_lib
!This program
IMPLICIT NONE
INTEGER seq(0:9)
INTEGER n
INTEGER l
INTEGER8 pn
POINTER (pn, l)
! real
8,DIMENSION(2) :: Az_min_max

print*
print*,'seq = ’
do n = 0, 9, 1
seq(n) = n
print*,seq(n)
end do

print*, ‘Calling external module…’
print*
print*, ‘---------- external modulde output start ----------’
print*

n = 10
pn = loc(n)
CALL external_processing(seq, n, pn)

print*
print*, ‘---------- external modulde output end ----------’
print*
500 print*,‘Done’


print*,'seq = ’
do n = 0, 9, 1
print*,seq(n)
end do

print*

END PROGRAM load_lib

-----------------------------> end of Fortran code <--------------------------

C++ code module: ---->


#include <stdio.h>
#include
#include
#include
#include <math.h>

template
class VectorOps
{
public:
VectorOps() {};
VectorOps(int len)
{
setLength(len);
}

void setLength(int len)
{
_len = len;
std::cout << std::dec << " VectorOps::setLength():: length set to: " << _len << std::endl;
}

VectorOps& operator <<(T *);
VectorOps& operator >>(T *);
void inc();
void sqr();

protected:
int _len;
std::vector _data;
};

template
VectorOps& VectorOps::operator <<(T* input_seq)
{
for(int i = 0; i < _len; i++) {
data.push_back(input_seq);
}

std::cout << " input sequnce received" << std::endl;

return this;
}

template
VectorOps& VectorOps::operator >>(T
output_seq)
{
for(int i = 0; i < _len; i++) {
output_seq = _data;
}

std::cout << " output sequnce transmitted" << std::endl;

return *this;
}
template
void VectorOps::inc()
{
for(int i = 0; i < _len; i++) {
_data++;
}

std::cout << " stored sequence incremented" << std::endl;
}

template
void VectorOps::sqr()
{
for(int i = 0; i < _len; i++) {
data = pow(data, 2);
}

std::cout << " stored sequence squared" << std::endl;
}

extern “C”
{

void external_processing
(int *seq, int *n, int **pn)
{
std::cout << " library function received " << std::hex <<
(long) n <<
" " << (long) (*pn) <<
std::endl;

VectorOps vo(*n);

vo << seq;
vo.inc();
vo.sqr();
vo >> seq;
}

}

Same method, you just need to change the flag names:

% pgfortran -c -Mcray=pointer -O3 main.for -Mfree
% pgc++ -c ext_lib.cpp
% pgfortran -o load_lib.exe ext_lib.o main.o -pgc++libs
% ./load_lib.exe

 seq =
            0
            1
            2
            3
            4
            5
            6
            7
            8
            9
 Calling external module...

 ---------- external modulde output start ----------

 library function received 7fffffffdfc4 7fffffffdfc4
 VectorOps::setLength():: length set to: 10
 input sequnce received
 stored sequence incremented
 stored sequence squared
 output sequnce transmitted

 ---------- external modulde output end ----------

 Done
 seq =
            1
            4
            9
           16
           25
           36
           49
           64
           81
          100