Hello,
We’ve encountered a critical issue with the new linker in Xcode 15’s CLT16 (version 16.1.0.0.1.1729049160) that prevents the proper initialization of BLOCK DATA .
I’m using GNU gfortran installed via MacPorts
gcc version 13.3.0 (MacPorts gcc13 13.3.0_2+stdlib_flag)
Currently, the workaround is to use the -ld_classic linker option. However, this option is deprecated and will be removed in a future release, as indicated in the Xcode release notes.
Here’s a minimal example that reproduces the problem:
I’m sure the real code you are working with is more complicated, but the long term answer is that block data is obsolete, as are common blocks. The “correct,” long-term solution would be
bd.f
module bd
double precision :: am(2)
integer, private :: i
data ( am(i), i = 1, 2 ) /
& 3.72738025692891D+00, 2.80839223660482D+00/
end module
I 100% agree with @everythingfunctional. Convert to a module and be happy. If there are a lot of files that include the common block, you can even temporarily keep the common statement inside the module while converting to simply useing the module.
For historic completeness though, when a block data program unit resides in a library, you may need a external statement (as in external bd) in your main program to get the linker to recognize things. This is not needed when using modules.
One general approach that seemed to work with most compilers during the f77 era was to place the block data into the same file as the main program. Maybe that will still work with the modern combination of compilers, linkers, and library files.
That would work - because the linker doesn’t need to access the block data unit from the library. Bit of a pain when you have a suite of programs that all access the same library and don’t want to replicate the block data unit (or use includes) in all of their source files.
Technically the external trick wouldn’t work in f66 - because naming block data units wasn’t Standard until f77. However it was a somewhat common extension in f66 compilers.