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

Program will not load DLL

aelliott
Beginner
1,103 Views
I created a trivial DLL from the following code:

INTEGER(4) FUNCTION DUMMY(X)
!DEC$ ATTRIBUTES DLLEXPORT :: dummy
REAL(8) X
DUMMY = NINT(X)
RETURN
END FUNCTION DUMMY

This compiles and links fine as shown here:


C:\\projects\\GEWind\\loaddll>ifort -dll myfunc.f90
Intel Visual Fortran Intel 64 Compiler XE for applications running
on Intel 64, Version 12.0.4.196 Build 20110427
Copyright (C) 1985-2011 Intel Corporation. All rights reserved.

Microsoft Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation. All rights reserved.

-out:myfunc.dll
-dll
-implib:myfunc.lib
myfunc.obj
Creating library myfunc.lib and object myfunc.exp

I then built a trivial program to test the loading of a DLL:

PROGRAM testload
USE IFWIN
!DEC$ ATTRIBUTES DLLIMPORT :: dummy
! check to learn how to load and use a dll
INTEGER(HANDLE) dllhandle, ires
dllhandle = LoadLibrary('myfunc.dll'C)
write (*,*) ' DLL handle = ', dllhandle
END PROGRAM testload

This also compiles and links without a peep:

C:\\projects\\GEWind\\loaddll>ifort testload.f90
Intel Visual Fortran Intel 64 Compiler XE for applications running on
Intel 64, Version 12.0.4.196 Build 20110427
Copyright (C) 1985-2011 Intel Corporation. All rights reserved.

Microsoft Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation. All rights reserved.

-out:testload.exe
-subsystem:console
testload.obj

Running testload, however, returns 0 for dllhandle and brings up a runtime error box:

R6034
An application has made an attempt to load the C runtime library incorrectly.
Please contact the application's support team for more information.

I can't figure out where the problem is. Anyone able to help?

Additional info: OS=Win7 pro, SP1, 64-bit
Visual Studio 2008, v9.0.21011.8 RTM
Fortran as shown above
Also tried it without the C qualifier on the file name - same results.

0 Kudos
6 Replies
Steven_L_Intel1
Employee
1,103 Views
That error usually means that the program links to one of the MSVC DLLs (which a Fortran DLL will by default), but either the wrong version of that DLL is present or a local copy of the DLL (MSVCR90.DLL for example)

What does Dependency Walker say?
0 Kudos
aelliott
Beginner
1,103 Views
Steve:

Thanks. depends gives a loading error. I am attaching the screen output, which seems to support your idea that mixed up DLLs are being referenced, but I am not sure how, since I am working from the command line and I did a full uninstall/reinstall of VS2008 and the compiler last Firday. There is no local copy of msvcr90.dll.

Andy Elliott
0 Kudos
Steven_L_Intel1
Employee
1,103 Views
Well, Depends may not be giving the correct answer here because of the way PATH works - did you load the x64 version of Depends? Are you running your program from a "Intel 64" compiler build environment session?
0 Kudos
aelliott
Beginner
1,103 Views
Steve:

Yes, I am running from a 64-bit build environment window. I downloaded the 64-bit version of depends and there the errors disappear and everything looks OK, I think? Fill attached as capture2.png.

Andy
0 Kudos
Steven_L_Intel1
Employee
1,103 Views
Ah - try this. Set the Libraries > Use Runtime Library property of the executable to "Multithreaded DLL" and rebuild.
0 Kudos
aelliott
Beginner
1,103 Views
I rebuilt the testload program based more closely on the example given in Samples diretory in DLL.zip. (I just discovered that in the v12 installation.) This includes a lot more code than would at first seem to be required, but after the rebuild, and following very carefully the build steps in the batch example, it does work. :)

So I recommend anyone else with similar problems also refer to that sample.
0 Kudos
Reply