shared memory in Fortran DLL's

shared memory in Fortran DLL's

A question regarding how dll's are implemented in Visual Fortran.

We have a large global library of code that we would like to implement as a dll (this is a library being ported from VMS).

In standard Windows DLL's, my understanding is that applications that use the dll share the code (i.e. functions) exported by the .dll, but that each application gets their own copy of an data (i.e. variables) used by the DLL.

In Fortran dll's, is this the default case as well? For example, suppose that the dll exports a variable , say, an integer x. We would want each application to have it's own copy of x that could not be corrupted by x being set by another application. (I understand that we could share common blocks across processes, but in this case, we would want the opposite to take place).

I have looked through the Visual Fortran Programmer's guide, but find the description of dll functionality a little confusing. Also, are there any different calling conventions necessary when using a .dll written in Fortran? I wouldn't think so, but you never know..

Any help would be appreciated!

Thanks -

Chris

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

A Fortran DLL IS a "standard Windows DLL". By default, each application which uses the DLL gets its own copy of the read/write data in the DLL - just like OpenVMS shareable images. Also as on OpenVMS, you can use linker options to specify that the read/write data should be shared across applications, but that is not the default.

As for calling, there is no difference between calling a Fortran routine in a DLL and calling one that is supplied in object form (or just elsewhere in your project). As on OpenVMS, a DLL is really just a pre-linked collection of routines (and data).

Steve

Steve - Intel Developer Support

Steve -

Thanks.. I have tried this and am experiencing the following problem:

a. In a dll project, I have a module that declares a variable, say:

integer x

b. I use the DLL EXPORT attribute for x
c. When I build the dll, I get a message warning me that I have link error 4049 - local variable x exported..
d. When I run an app that references the dll, I immediately get an access violation at 0x00000005 during the call to GLOBALDLL!_CRT_INIT@12.

Any ideas?

Thanks -

Chris

I'm not sure if DLLEXPORT of a module variable works yet - a COMMON works, and can be treated the same as a C "extern". I know the documentation isn't too clear on this, but the original intent was to support this for COMMONs only. We did add support for module variables (has to be at the outer level of a module), but it didn't all work quite right in 6.5. Should be better for 6.5A (January).

Steve

I'm not familiar with the access violation you describe, but it may be related to the other problem.

Steve - Intel Developer Support

We have people dllexporting module variables, including allocatable arrays. I know of only one "peculiararity", but I'm pretty certain it was "programmer error".

The documentation for link error LNK4049 is 'exported symbol "symbol" also imported' (The symbol was both exported from and imported to the program). I've not seen an error like "local variable x exported.. "

Maybe Chris could post a sample that generates his problem. I'm sure someone could point out the problem.

-John

Leave a Comment

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