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

Fortran dll file output truncation issue

sjs65
Beginner
1,326 Views
I'm experiencing unexpected behavior when using fortran formatted output to a text file from within my fortran DLL. Details below.

I have some subroutines that perform formatted fortran output to a particular unit number opened in the calling program. When those subroutines are included in the main program source file and compiled/linked, the i/o works as intended. When the i/o subroutines are linked as a DLL (no code changes), the output to the text file is truncated. I have verified that the write statements are executed properly by redirecting output for that unit number to stdout (conout$). The problem only seems to exist when trying to write that information to a file.

Please help.

Thanks.
0 Kudos
10 Replies
james1
Beginner
1,326 Views
The calling program needs to be linked against the DLL version of the runtime library, as in /libs:dll.

James
0 Kudos
sjs65
Beginner
1,326 Views

I tried this and still have the problem.
0 Kudos
james1
Beginner
1,326 Views
If you can reduce your problem to a small sample then try posting it. Otherwise you can try to do an INQUIRE inside your DLL routine on the unit to see if it is open already or not. The reason for using /libs:dll was to ensure that you are using the same version of the RTL in both the DLL (where using the /libs:dll is default if building from VS) and the main program (where using /libs:dll is not the default), otherwise what would essentially be happening is the DLL would be doing I/O to that unit ever formally opening the unit from its point-of-view. In that case I would expect an INQUIRE would show that the unit is closed prior to doing the first WRITE.

James
0 Kudos
sjs65
Beginner
1,326 Views
Thanks for the help.

Turns out the /libs:dll compiler option did solve the problem. I forgot to use that option for my executable the first go-round.
0 Kudos
Xj_Kong
Novice
1,326 Views

I am using CVF6.6. In the main program,I open file unit 10 and append some text within dll to the same unit 10, but there are two files generated and fort.10 is obviously from dll.

How can I set continuity of I/O between code residing in a main program and code residing in a DLL?

I tried several times in project->setting->link by adding /libs:dll, no improve abtained.

I really appreciate your kind help.

0 Kudos
Steven_L_Intel1
Employee
1,326 Views
Did you make this change for the executable project? Make sure that the libraries setting for both is DLL.
0 Kudos
Brett_B_
Beginner
1,326 Views
Steve,

I am having a similar problem to this thread. dll writing output to fort.2000 rather than already opened unit 2000. This is with visual studio 2005, ifort 10.0.3847. I have tried several combinations of the runtime library options (/libs), always keeping executable and dll projects the same to no avail. I also still use cvf when I can, and in that, if the runtime library linking is misaligned, I get the same behavior as I am getting with ifort, but, when the runtime library linking is aligned, it works correctly.

Thanks
0 Kudos
Steven_L_Intel1
Employee
1,326 Views
All I can say is that if the use of DLLs is consistent, then it should work. How about this - download Dependency Walker, run it, drag your executable onto it, do a File > Save of the information and attach the .dwi file to a reply here. What you want to look for is both the EXE and the DLL referencing the same libifcoremd.dll.
0 Kudos
Brett_B_
Beginner
1,326 Views
Thanks for your reply.

I was telling it to ignore libifcoremdd.lib (ignore specific library) because I was getting severall of the following type of link errors:

Error 4 error LNK2005: _for_emit_diagnostic already defined in libifcoremdd.lib(libifcoremdd.dll) libifcoremt.lib

Also ignored MSVCRTD.lib because of:

Error 15 error LNK2005: _exit already defined in MSVCRTD.lib(MSVCR80D.dll) LIBCMTD.lib


Ignoring both of these allowed it to link and run, but I got the issue with the writing to the unit. I tried ignoring just MSVCRTD.lib, and it links, but then I get a stack overflow at a call to a subroutine with no arguments.

I also have a static library (mix of C and fortran) that is included in the executable project - is this why I am getting these "already defined" errors? I did not think the settings used to build the static library mattered, and, is it even proper to use /libs:dll when builing a static library?

Thanks very much for your help ... saw some of your blog discussing New Hampshire - I used to live in Portsmouth and I really miss it.

0 Kudos
Steven_L_Intel1
Employee
1,326 Views
What this tells me is that you do NOT have all the projects set to the same set of libraries. Yes, how you have static libraries built matters too. Make sure the setting is consistent across all the projects, including C, and that they are ALL referencing the same set of DLL libraries (either all debug or none debug.) Don't have any that reference static libraries.
0 Kudos
Reply