The main program uses modules that are built in a DLL. One of the DLL procedures opens a log file. I'd like to be able to write to the log file from the main program. I can make the file unit number known to the main program via !DEC$ ATTRIBUTES DLLEXPORT, but of course that doesn't do anything for me - lines written to unit number 11 just go to fort.11. Is there a simple way to do what I want to do?
Yes - make sure that your main program links against the DLL form of the Intel run-time libraries. This has been the default in Visual Studio for several releases now, but an older project may not have it. (Your DLL must also link to the DLL libraries.) The project property for this is Fortran > Libraries > Use Runtime Library > Multithread DLL. Make sure that both your DLL and the main program have the same setting here.
What's happening is that your main program and your DLL each have their own copy of the run-time library, so they don't talk to each other.
I changed the main program project property from Multithread to Multithread DLL, but when I run the program I get this error:
An application has made an attempt to load the C runtime library incorrectly.
Maybe my compiler version (11.0.075) is too old for this to work. I know, you'll say my compiler is obsolete, but it works fine for my purposes.
1) Make sure your DLL project has the same setting. Don't mix debug and non-debug.
2) If you have any OTHER projects (C/C++, for example) in the application, make sure that their setting for runtime libraries also matches.
I checked that the correct DLL is linked. Dependency Walker doesn't show anything odd, as far as I can tell. Both the DLL and the exe use c:\windows\system32\MSVCRT.DLL. Are there other libraries I should look for?