Accessing Fortran Common Blocks from C

Accessing Fortran Common Blocks from C

I am trying to create a Fortran DLL containing a Common Block which I can then use to link with a C program to resolve an external name.
The DLL appears to create successfully but when I link the C program I always get an unresolved external symbol. This code does work when the Fortran part is not built as a DLL. Does anybody have any ideas ?
I have shown my code below.

Fortran DLL:
!DEC$ DEFINE GLOBAL_EXPORT
block data
include 'GLOBAL01.FI'
data PRBUZ /0.0/
end

GLOBAL01.FI include file:
REAL*8 prbuz
COMMON /GLOBAL01/ prbuz
!DEC$ IF DEFINED (GLOBAL_EXPORT)
!DEC$ ATTRIBUTES DLLEXPORT :: /GLOBAL01/
!DEC$ ELSE
!DEC$ ATTRIBUTES DLLIMPORT :: /GLOBAL01/
volatile /GLOBAL01/
!DEC$ ENDIF

C program:
#include
struct g1 struct
{
double prbuz;
};
extern struct g1 global01;
main()
{
global01.prbuz = 50.0;
}

When this is linked against the above DLL I always get GLOBAL01 reported as undefined.

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Actually, I'd bet that you get _global01 undefined. C is case-sensitive - change the name to GLOBAL01 in the C code and this should work, though I think you also need a _dllimport pragma in there somewhere...

Steve

Retired 12/31/2016

Leave a Comment

Please sign in to add a comment. Not a member? Join today