Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Block Data in exe but not com dll

Intel_C_Intel
Employee
947 Views

I've recently converted two projects from Visual Studio 6 / Compaq Fortran to Visual Studio 2005 / Intel Fortran 9.1.

The first project isjust fortran with a main program, and it compiles and links to produce a console application executable.

The second project uses the same fortran (without the main program), but has a C++ wrapper, and it compiles and links to produce a COM dll.

Now in the fortran, there are some block data routines, consisting of common blocks with data statements.

When I run the .exe project in debug, I can see that the block data has set numbers in the common blocks. However, when I run the COM dll in debug, the numbers are not in the common blocks. The block data has been ignored.

I got around the problem by simply changing the block data routines into subroutines, and calling the subroutine at the beginning of the calculationi.e calling subroutines with just common blocks and data statements.

I'd really like to understand what's going on though with the block data, and whether there is a better solution.

Thanks in advance.

Andrew

0 Kudos
5 Replies
Steven_L_Intel1
Employee
947 Views
First, does the program also not see the initialized values? It may be the debugger sees something different. Is the source with the BLOCK DATA part of the project or is it in a .lib that gets linked to? My guess is that the object module with the BLOCK DATA is not being linked in. Use an EXTERNAL declaration in one of the routines to name the BLOCK DATA subprogram to make sure it is referenced.
0 Kudos
Intel_C_Intel
Employee
947 Views

Yes, all thefortran source including the block data is in a .lib, with the C++ being the main part of the project. I'll try adding EXTERNALin one of theroutines.

Thanks.

0 Kudos
Steven_L_Intel1
Employee
947 Views
I'm sure that will fix it. You have to do this when a BLOCK DATA subprogram is in a library. WIth CVF, the Fortran and C++ code was in the same project so you didn't have this issue.
0 Kudos
Intel_C_Intel
Employee
947 Views

It worked. By referencing the block data with EXTERNAL in another subroutine, the block data object module got linked into the library.

I understand that block data is not recommeded nowadays, but is this a linker problem? Or is it forcing good practice in making you declaresubprograms that you can't explicitly call?

Thanks again.

0 Kudos
Steven_L_Intel1
Employee
947 Views
This is a general issue on every platform I know of. Linkers pull from libraries only those object modules which satisfy external references. No reference, no pull. There is nothing in the Fortran language except the EXTERNAL statement to create such a reference for BLOCK DATA, and the language explicitly calls out EXTERNAL for just this purpose, to "confirm" that a BLOCK DATA subprogram is part of the application.

So yes, it is good practice to name BLOCK DATA in an EXTERNAL. By the way, I know of no reason that BLOCK DATA should be considered "not recommended", though COMMON is frowned upon by modern language purists who would rather you use module variables. They have a point - if you're writing new code.
0 Kudos
Reply