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

Consol App Executables Vs. Libs

rocket_man
Beginner
197 Views

Would someone direct me to some reference material on howCOMMON and BLOCK DATAare handled differentlywhen compiling consol applications executablesversusstaticlibrary for the same FORTRAN routine.

Here is a brief description of my challenge: I have a FORTRAN program that compiles and runs correctly when I compile as a consol application executable. Now I need to make this program a library, I changed the PROGRAM XYZ to SUBROUTINE XYZ and added the following compiler directive "!DEC$ ATTRIBUTES DLLEXPORT :: XYZ". The library compiles and runs, but the outputis not correct. Using WRITE statements in both the consol application and libraryversions we traced it down to variables in COMMON blocks that were not the expected values in the library.

Thanks!

0 Kudos
1 Reply
Steven_L_Intel1
Employee
197 Views
When you are building an application which compiles the source of the BLOCK DATA, Visual Studio makes sure that the object file for the BLOCK DATA is included in the link. When you have a BLOCK DATA in a library, the linker doesn't know to pull it out unless something references it. You are supposed to use EXTERNAL for this.

For example, if the BLOCK DATA is named MYBLOCK, add:

EXTERNAL MYBLOCK

to something in the code that needs the COMMON.

I'm a bit confused about your mention of DLLEXPORT - are you building a DLL? If so, and if you expect the COMMON to be shared between the DLL and the console program, you have more work to do - mainly, add a:

!DEC$ ATTRIBUTES DLLEXPORT :: /commonname/

directive for the COMMON in the BLOCK DATA subprogram and add a

!DEC$ ATTRIBUTES DLLIMPORT :: /commonname/

in any source that references the COMMON.

If you are building a static library, you don't need DLLEXPORT/DLLIMPORT.
0 Kudos
Reply