- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to access a common block exported from a Fortran routine which resides in a DLL from a C routine. The problem seems to be with the leading underscore appended to the name. I have tried using STDCALL and C attributes and playing with how the common block is named in the C code with no success. I still receive the linker error for an unresolved external symbol.
The following sample code illustrates the problem. The C code is in the file c1.1 .
void MyCFunc()
{
int i1;
float r1;
double d1;
extern struct {
int var_i;
float var_r;
double var_d;
} CMN_BLK;
F2();
i1 = CMN_BLK.var_i;
r1 = CMN_BLK.var_r;
d1 = CMN_BLK.var_d;
}
SUBROUTINE F2
!DEC$ ATTRIBUTES DLLEXPORT :: F2
!DEC$ ATTRIBUTES DLLEXPORT :: CMN_BLK
INTEGER :: var_i
REAL :: var_r
REAL*8 :: var_d
COMMON /CMN_BLK/ var_i, var_r, var_d
var_i = 100
var_r = 200.0
var_d = 300.0d0
RETURN
END SUBROUTINE F2
c1.obj : error LNK2001: unresolved external symbol _CMN_BLK
The following sample code illustrates the problem. The C code is in the file c1.1 .
void MyCFunc()
{
int i1;
float r1;
double d1;
extern struct {
int var_i;
float var_r;
double var_d;
} CMN_BLK;
F2();
i1 = CMN_BLK.var_i;
r1 = CMN_BLK.var_r;
d1 = CMN_BLK.var_d;
}
SUBROUTINE F2
!DEC$ ATTRIBUTES DLLEXPORT :: F2
!DEC$ ATTRIBUTES DLLEXPORT :: CMN_BLK
INTEGER :: var_i
REAL :: var_r
REAL*8 :: var_d
COMMON /CMN_BLK/ var_i, var_r, var_d
var_i = 100
var_r = 200.0
var_d = 300.0d0
RETURN
END SUBROUTINE F2
c1.obj : error LNK2001: unresolved external symbol _CMN_BLK
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You need to tell the C compiler that the struct is DLLIMPORTed. You do this by adding __declspec(dllimport) after "extern".
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You need to tell the C compiler that the struct is DLLIMPORTed. You do this by adding __declspec(dllimport) after "extern".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Steve Lionel (Intel)
You need to tell the C compiler that the struct is DLLIMPORTed. You do this by adding __declspec(dllimport) after "extern".
Thanks Steve, that works fine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve Lionel (Intel) wrote:
You need to tell the C compiler that the struct is DLLIMPORTed. You do this by adding __declspec(dllimport) after "extern".
i want to access data from the common block
but my program are write in object pascal ,
what should i do
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You will need to ascertain the external interfaces that your Pascal compiler supports, and examine whether it is feasible to call a Fortran DLL from object pascal, or whether it would be better to use C code as an intermediary.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page