Standard-conforming way of doing `!DEC$ attributes dllexport`

I recall DEF files being mentioned on Fortran Discourse before. After searching for a while I found these threads:

(@FortranFan, do you have other posts showing the usage of module-definition files?)

Here is the explanation of the solution used from the CMake file of PRIMA:

# On Windows, when building shared libs, visible functions must be explicitly listed.
# Unlike C there are no standard keywords to do this in Fortran but only compiler-specific pragmas:
# !GCC$ attributes dllexport :: bobyqa_c
# !DEC$ attributes dllexport :: bobyqa_c
# the downside is unwanted -Wattribute warnings.
# Another option is to use .def files referencing exported symbols:
# https://learn.microsoft.com/en-us/cpp/build/exporting-from-a-dll-using-def-files?view=msvc-170
# Mangling is different between GNU and Intel/LLVM compiler families so we use a dedicated file for each.
# Symbol names can be seen in object files with the dumpbin tool (or objdump) to write a new .def:
# dumpbin /symbols cobyla.f90.obj
# 017 00000000 UNDEF  no_type       External     | COBYLA_MOD_mp_COBYLA
# x86_64-w64-mingw32-objdump -t cobyla.f90.obj
# [  4](sec  1)(fl 0x00)(ty   20)(scl   2) (nx 0) 0x000000000000218b __cobyla_mod_MOD_cobyla

It would be nice mentioning the DEF files in the Fortran-Lang mini book on Managing libraries.

I agree with @shahmoradi that throwing a warning for what is essentially a comment is questionable. It would be worth bringing this up on the Intel forum.

2 Likes