Quantcast
Channel: Intel® Fortran Compiler for Linux* and macOS*
Viewing all articles
Browse latest Browse all 2583

How to allocate a Fortran dynamic array in a dynamic-linked library written in C++?

$
0
0

Hello,

I'm trying to allocate a Fortran dynamic array in a member function of
a dynamic-linked library written in C.
The compiling and linking is success, but the exacution afterwards has
some problems.
It get stuck at the "new" sentance in the dynamic-linked library member function.

The C++ codes (secso.cpp) for dynamic-linked library:

#include <iostream>
extern "C"
{
    int f(int & i, char * name, double * array)
    {
        int j,k;

        std::cout << "The allocation 1"<<std::endl;
        array = new double [9*3];
        std::cout << "The allocation 2"<<std::endl;
        for (j=0;j<9;j++)
        {
            for (k=0;k<3;k++)
            {
                array [j*3+k] = double((j+1)*10+k+1);
            }
        }

        return 0;
    }
}

The Fortran main function code (test.f90):

program test
implicit none

real(kind=8),  pointer :: array(:,:)

! External C style function
call f(array)

write (*,*) array
deallocate (array)

end program test

 

Make file (makefile):

SHELL = /bin/bash
test:
 icpc -shared -fPIC -o libsec.so secso.cpp
 ifort -assume nounderscore -o test.exe test.f90 -L. -lsec

What should I do?
Any advise would be helpful, thanks in advance.


Viewing all articles
Browse latest Browse all 2583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>