Search code examples
fortranlibraries

lib.exe : Controlling symbol inclusion with duplicate common blocks


I am using lib.exe to create a library from Fortran compiled objects (ancient F77 using Intel compiler 18). The Fortran has duplicate common blocks of different sizes. It also has duplicate methods. This is legacy code with a clunky sort of overloading.

For a duplicate method lib.exe seems to always take the method from the first object.

For a duplicate common block it take it from the last object in common.lib

lib.exe /OUT:target.lib pmk.obj lib.exe target.lib common.lib

The common blocks only differ in array sizing e.g.

COMMON /CPSTKC/ ISTACK(6,200)

vs

COMMON /CPSTKC/ ISTACK(6,15)

And I need the larger one.

I can't just reverse the lib.exe order as then it takes the wrong method. Also I don't want to touch common.lib if I can help it, but pmk.f is fair game.

How can I understand what is happening here so I can get it to behave?


Solution

  • Because of my status, I can't make comments, but since no one else chimed in, here are my thoughts. Do you have BLOCKDATA units(this initializes Commons) in this program? If not you could add this at the end of your main program or create separately. This could specify the storage shape/size of the arrays. Since they are not executable they can't be linked from a library so they need to be in something explicitly linked in the link step - which might make it easiest to place in the main module. You get the advantage of explicitly and before any executable statements, initialization of common data ( a common source of bugs).

    BTW, the duplicate methods you mention sounds very risky and compiler/linker/version dependent. (the common aliasing less so, since I think it was specified in at least F77 stds if not later) why would you have the same method in the same code base twice?