From: Pedro567 on

We are having a problem to match properly a C struct exported as dll
using GNU g++ 4.4.0 with
a COMMON block in Fortran using GNU gfortran 4.4.0. Tt works properly
in Linux version, but not with
Mingw. Probably we are missing something in this platform. Any help
will be welcomme.

Code in C++ (compiled as a dll):
extern "C"
{
extern struct {
int n;
int k;
} area_ ;
}

extern "C" __declspec(dllexport) void view_()
{
area_.n= 83;
printf("c++, n=%d , k=%d \n",area_.n,area_.k);
return;
}

Code in FORTRAN (main program calling the previous dll):
BLOCK DATA t
INTEGER N,K
COMMON /AREA/ N,K
END

PROGRAM P456
COMMON /AREA/ N,K
N = 3
K = 6
WRITE(*,*) N,K
CALL view
WRITE(*,*) N,K
END PROGRAM

We add an extra C file to the dll for compiling independly of FORTRAN:
__declspec(dllexport) struct {
int n;
int k;
} area_ ;

The problem is that when we compile and execute the program we obtain:
3 6
83 0
3 6
instead of
3 6
83 6
83 6

The AREA common block in FORTRAN does not point to the same struct
area in C++ dll, why?

Thanks for any help
Pedro

From: Pedro567 on
On 31 mar, 14:47, Tobias Burnus <bur...(a)net-b.de> wrote:
> I ask Kai Tietz, who is MinGW64 expert, and he said that you are missing
> a __declspec(dllexport) for "extern":

In our example (more ellaborated) we used this directive but without
success.
extern "C" __declspec(dllexport) struct {
int n;
int k;
} area_ ;


> As better? alternative he suggest to use the linker option
> --enable-runtime-pseudo-reloc-v2 (as pass-on option for the compiler:
> -Wl,--enable-runtime-pseudo-reloc-v2); however, that requires a rather
> new MinGW runtime and binutils.

We have tried those options in the linker but the output is wrong
again.

Thanks anyway Tobias for your help. We continue the search.
Pedro
From: Chris Hulbert on
On Mar 31, 9:10 am, Pedro567 <p...(a)ecosimpro.com> wrote:
> On 31 mar, 14:47, Tobias Burnus <bur...(a)net-b.de> wrote:
>
> > I ask Kai Tietz, who is MinGW64 expert, and he said that you are missing
> > a __declspec(dllexport) for "extern":
>
> In our example (more ellaborated) we used this directive but without
> success.
> extern "C" __declspec(dllexport) struct {
>   int   n;
>   int   k;
>
> }  area_ ;
> > As better? alternative he suggest to use the linker option
> > --enable-runtime-pseudo-reloc-v2 (as pass-on option for the compiler:
> > -Wl,--enable-runtime-pseudo-reloc-v2); however, that requires a rather
> > new MinGW runtime and binutils.
>
> We have tried those options in the linker but the output is wrong
> again.
>
> Thanks anyway Tobias for your help. We continue the search.
> Pedro

I seem to recall having issues accessing "data" exported by DLLs. I
have not used the GNU compilers on mingw for a while, but for other
fortran compilers on Windows, I think have had to use the "!DEC$
ATTRIBUTES DLLIMPORT" for the common block to get it to use the data
in the DLL and not its own.
From: Pedro567 on
On 31 mar, 20:19, Tobias Burnus <bur...(a)net-b.de> wrote:
> Chris Hulbert wrote:
> > I seem to recall having issues accessing "data" exported by DLLs. I
> > have not used the GNU compilers on mingw for a while, but for other
> > fortran compilers on Windows, I think have had to use the "!DEC$
> > ATTRIBUTES DLLIMPORT" for the common block to get it to use the data
> > in the DLL and not its own.
>
> If this is the case, one could try:
>
> !GCC$ ATTRIBUTES DLLIMPORT :: common_name
>
> cf.http://gcc.gnu.org/onlinedocs/gfortran/GNU-Fortran-Compiler-Directive...
>
> Note: This is a new GCC 4.5 feature (cf.http://gcc.gnu.org/gcc-4.5/changes.html). I stress this because
> previous GCC Fortran versions simply ignore this line as comment. (I
> think DLLIMPORT/DLLEXPORT has not yet been tested for COMMON blocks -
> though it looks (from the gfortran source code) as if should work.)
>
> Tobias,
> who has not compiled software on/for Windows for many years

Unfortunatelly we tried also this solution but in Mingw is not working
at all.