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

Using a DLL on another System fails

mfangmeyer
Beginner
2,348 Views
Hi!

I'v built a Fortran DLL which can be called from a .NET application on my system. A relative path is been set and everything works fine.
Copying the EXE and DLL to another system (same directory) leads to a calling failure. The DLL can't be found. What could be the reason for that?

Best regards, Marc
0 Kudos
17 Replies
Wendy_Doerner__Intel
Valued Contributor I
2,348 Views
Your DLL needs to be on the PATH for the system you have moved it too and you need to add the the import .LIB file to the image on the new system. These are detailed in steps 1, 5 and 6 below in this excerpt from the documentation. Are any of these the cause of your problem?

------

Wendy

Attaching or including files in a post




To use the DLL from another image:
  1. Add the import .LIB file with its path and library name to the other image.

    In the integrated development environment, add the .LIB import library file to your project. In the Project menu, select Add Existing Item... . If the importing project and the DLL are in the same solution, you can add the DLL project as a dependency of the importing project instead.

    On the command line, specify the .LIB file on the command line.

    The import .LIB file contains information that your program needs to work with the DLL.

  2. If your DLL exports data, consistently use the same property page options in the Fortran Data category /align option as was used to create the DLL. In the Fortran Data category, specify the appropriate values for Common Element Alignment (common block data) and Structure Member Alignment (structures in a module). This sets the /align option, which specifies whether padding is needed to ensure that imported data items are naturally aligned.

  3. In the Project Property Pages dialog box, make sure the type of libraries specified is consistent with that specified for the Fortran DLL.

  4. If you need to specify linker options:

    • In the IDE, specify linker options in the Linker category.

    • On the ifort command line, place linker options after the /link option.

  5. Copy the DLL into your path.

    For an application to access your DLL, it must be located in a directory on the search path or in the same directory as the main project. If you have more than one program accessing your DLL, you can keep it in a convenient directory identified in the environment path. If you have several DLLs, you can place them all in the same directory to avoid adding numerous directories to the path specification.

    You should log out and back in after modifying the system path.

  6. Build the image that references the DLL.

    When using the visual development environment:

    • Like building other projects in the integrated development environment, use the Build menu items to create the executable.

    When using the command line:

    • Specify the import library at the end of the command line.

    • If your DLL exports data that will be used by the application being built, specify the same /align options that were used to build the DLL.

    • If you are building a main application, omit the /dll option.

    • When building a Fortran DLL that references another DLL, specify the /dll option.

    For example, to build the main application from the command line that references 4-byte items in a common block defined in dllfile.dll:




0 Kudos
Steven_L_Intel1
Employee
2,348 Views
With a .NET application you usually specify the path to the DLL. More likely the problem is that your DLL is dependent on another DLL not present - the error message you get from .NET applications is misleading in this case.

First, make sure your DLL was built as a Release configuration and not Debug. Second, you'll need the Intel Fortran redistributables inatalled on the target system - you can download an installer from the Intel Registration Center alongside the compiler. You may need a Microsoft Visual C++ redistributables insaller as well.
0 Kudos
DavidWhite
Valued Contributor II
2,348 Views
To check which DLL is causing the problem, I suggest you try Dependency Walker todiagnose the problem. This can be downloaded for free from dependencywalker.com

Regards

David
0 Kudos
mfangmeyer
Beginner
2,348 Views
Many thanks to you all! I could fix it by building the DLL as release and especially by installing the "Redistributable library package for IA32".

Nevertheless I'm interested in a solution without installing this package. Therefore I have checked the items 1-6 in Wendy's post. Yet nothing helps. But there must be some Linker option for that?!

Edit: Dependency Walker says that the DLL is dependent on another DLL. Is it possible to link this libary statically?
0 Kudos
Wendy_Doerner__Intel
Valued Contributor I
2,348 Views
Yes you can link statically instead of using DLLs. So you would provide a library on your other systems that you link statically too.

Here is how to create a static library from the documentation installed on your system or online.


------

Wendy

Attaching or including files in a post


To build a static library (Windows OS):

To build a static library from the integrated development environment (IDE), select the Fortran Static Library project type.

To build a static library using the command line:


  1. Use the /c option to generate object files from the source files:

    ifort /c my_source1.f90 my_source2.f90
  2. Use the Microsoft LIB tool to create the library file from the object files:

    lib /out:my_lib.lib my_source1.obj my_source2.obj
  3. Compile and link your project with your new library:

    ifort main.f90 my_lib.lib
0 Kudos
mfangmeyer
Beginner
2,348 Views
Hallo Wendy!

I think there is a misunderstanding. I don't want use a static liberay instead of a DLL. There are some dependencies to other DLLs. I just want to abrogate these dependencies by linking statically.

Regards
Marc
0 Kudos
mecej4
Honored Contributor III
2,348 Views
I just want to abrogate these dependencies by linking statically.

That is rather extreme. A more reasonable goal would be to build your DLL by linking against static versions of only those libraries that are required by the DLL but are not found (as DLLs) in every Windows installation. However, this can be done only if you have the necessary libraries on the build machine.
0 Kudos
mfangmeyer
Beginner
2,348 Views
I see, it's much better to install the Redistributable library package...

Today I tried to run a simple EXE on another system without this package. It did not run!
0 Kudos
Steven_L_Intel1
Employee
2,348 Views
You can link statically if you want, but do this only if the caller of the DLL is not Fortran. In the project properties, go to Fortran > Libraries and select "Multithreaded (/MT)" for "Use Run-Time Library".
0 Kudos
mfangmeyer
Beginner
2,348 Views
The caller is .NET, but fortran > Libraries -> "Multithreaded (/MT)" also doesn't work.
0 Kudos
Steven_L_Intel1
Employee
2,348 Views
"doesn't work" as in you get a DLL not found error? That should be easy to debug, then.
0 Kudos
mfangmeyer
Beginner
2,348 Views
Yes, there is a DLL not found error.
0 Kudos
Steven_L_Intel1
Employee
2,348 Views
Then either the path you have specified to the DLL is wrong, or there is a missing dependent DLL (which Dependency Walker should show.)
0 Kudos
mfangmeyer
Beginner
2,348 Views
It's not necessary to set a path to a DLL. It's a simple EXE that I want do execute. Anyway, installing the Redistributable Packages solves this problem.
0 Kudos
Steven_L_Intel1
Employee
2,348 Views
If you are invoking a DLL from a .NET application, you do need to specify the path to the DLL (if it's not already in PATH or a place that Windows will look for it). If installing the redistributables package fixed the problem, then DLL was not linked statically and Dependency Walker should have found the problem. Glad to hear that you solved it.
0 Kudos
mfangmeyer
Beginner
2,348 Views
Hi Steve,

but I tried to link the DLL statically. So far I have not managed it.

Marc
0 Kudos
Steven_L_Intel1
Employee
2,348 Views
What did you try and what goes wrong?
0 Kudos
Reply