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

my Fortran-DLLs for my students

Olaf
Novice
2,242 Views

Dear friends,

 

for years I programmed DLLs in FORTRAN in VS2017 and provided them to my students for using in an special application. Never there were any problems. But now these DLLs are not working on the student's computer both in Windows 10 and Windows 11. Only on my computer there are no problems, and I can use them in the mentioned application. I don't know how to fix it. May be, there can be some configuration setups. But I have no idea which one.

Can anybody help me?

 

Olaf from Austria

0 Kudos
1 Solution
Olaf
Novice
1,961 Views

Dear friends,

 

yesterday I found the solution.

My dll use additional dll's not only from windows but from a third party developer. I saw it in the dependency walker. On my computer these third party dlls are no problem, but on the students computers they were on a wrong place. if the students copied them to this directory, where the exe of the main application is still placed, all problems had disappeared.

But thank you all for your help. With my reduced soure the problems were not included. Afterwards I know this.

 

Many thanks

 

Olaf from Austria

View solution in original post

0 Kudos
15 Replies
FortranFan
Honored Contributor II
2,228 Views

FYI for other readers on the same inquiry at comp.lang.fortran:

https://groups.google.com/g/comp.lang.fortran/c/RlE6WyGyQD4/m/vEjRGMyyAAAJ

0 Kudos
Olaf
Novice
2,200 Views

Ja, sorry. Is this a problem? I hoped to contact more people.

And my stundent's tried the recommendations in the links above. But they doesn't help.

I really guess, there can be some wrong configuration setups.

 

Olaf

 

 

0 Kudos
JohnNichols
Valued Contributor III
2,193 Views

Put the dlls in a zip file and I can try them for you,  I have a lot of computers so it is not a problem.  

You did not give much info that makes it hard to help, what are the error messages that students are getting.  

 

0 Kudos
Olaf
Novice
2,185 Views

Ah John, many thanks.

Here is a very reduced and simple example.

In the zip file is a read.txt file with some details.

Thank you again, Olaf

0 Kudos
JohnNichols
Valued Contributor III
2,163 Views

I am using VS 2019, you should update 2017 is a bit behind.  

The zip file goes in

 

C:\Users\smith\Documents\Visual Studio 2019\Projects

 

Smith is the Smithsonian Name

0 Kudos
JohnNichols
Valued Contributor III
2,162 Views

Screenshot_20230205_032936.png

 

I tested it, download to downloads, extract in downloads, start, build and run and you get this screen.  CCCC is the initial compiler value, I set to 0 and then call your routine and get 1.  You need to make sure you have the variables in the correct form.  Adding intent inout would help a bit/ 

0 Kudos
Olaf
Novice
2,143 Views

Thank you John,

 

at first I do an update now (as you said). Next steps I do after that. But before the update I have a look as the program pieces you wrote for me.

 

Many thanks,

 

Olaf

0 Kudos
Olaf
Novice
2,116 Views

Hi John,

 

at least I changed to 64 bit.

The difference between your and my code: yours is an application, but I need unconditional a dll. But while linking my dll there is the mistake 1561 - no entry point.

Do I need a main proramm in the dll???? I can not imagine.

 

greetings

Olaf

0 Kudos
mecej4
Honored Contributor III
2,150 Views

The exported name in the DLL that you attached is _os_int@8, with an alias of os_int.

Note that both names are in lower case. External names in objects compiled by Intel compilers when targeting IA32 are usually upper case.

What is the expected name decoration in the applications that your students write and attempt to link to your DLL? Can you please be more explicit about what goes wrong than "DLLs are not working"? What is the error message, and under what circumstances is it seen?

0 Kudos
Steve_Lionel
Honored Contributor III
2,132 Views

Olaf, please show us the exact and complete error message that is seen when it "doesn't work". All we can do is guess, though @mecej4 made a useful observation. I would expect this behavior if the DLL was built with /iface:stdcall , which is a very bad idea.

0 Kudos
FortranFan
Honored Contributor II
2,126 Views

@Olaf ,

If you are willing, I suggest you now try a small test as shown below but without any of the complications with Visual Studio solution and project(s).  It requires a bit of typing but mostly you can copy-and-paste from this comment to somewhat ease that aspect.

  • First, note you currently have your Fortran "library" err.. DLL procedure as follows which is a compiler-dependent way of writing code

 

!
!23456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012
Function os_int(a)
!DEC$ ATTRIBUTES DLLEXPORT :: os_int
!DEC$ ATTRIBUTES STDCALL :: os_int
!   os_int - int
!   a      - int von a (int of this value will be calculated)
	IMPLICIT NONE
    double precision :: os_int, a
    os_int = int(a)
end function

 

Instead, I suggest you consider modern Fortran with its standard facilities and write your code as below - more on this in a later comment, depending on your interest in adopting this:

 

module OS_m
   use, intrinsic :: iso_c_binding, only : c_int, c_double
   implicit none
contains
   function os_int( a ) result(r) bind(C, name="os_int")
      ! Argument list
      real(c_double), intent(in) :: a
      ! Function result
      integer(c_int) :: r
      r = int( a, kind=kind(a) ) 
   end function 
end module 

 

  • Then please review this link from Microsoft and write a Windows-definition file toward the DLL of interest to you as follows, presume you will call it OS.def:

 

LIBRARY OS
EXPORTS
    os_int   @1

 

  • Now run the Intel Fortran provided command-line prompt shortcut and build the DLL as follows, here I show the one toward IA-32 target provided by Intel for Visual Studio 2022.  Note the OS.lib created by the linker, unless your students are performing run-time dynamic-loading of your DLL (this is more complicated but can provide certain flexibility), they will need this lib file.

 

C:\temp>ifort /c /standard-semantics OSInt.f90
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on IA-32, Version 2021.8.0 Build 20221119_000000
Copyright (C) 1985-2022 Intel Corporation.  All rights reserved.


C:\temp>link OSInt.obj /dll /def:OS.def /out:OS.dll
Microsoft (R) Incremental Linker Version 14.34.31937.0
Copyright (C) Microsoft Corporation.  All rights reserved.

   Creating library OS.lib and object OS.exp

C:\temp>

 

  • Now, note your student(s) may write C++ code to consume your DLL as follows, presume they call it c++.cpp file:

 

#include <iostream>
using namespace std;

// Function prototype for Olaf's Fortran library
extern "C" {
   int os_int( double& );
}

int main() {
   double foo = 3.14;
   cout << "os_int(&foo) returns " << os_int(foo) << endl;
}

 

  • Then using your lib file from the DLL build step above, they can build a program as follows:

 

C:\temp>cl /c /EHsc /W3 c++.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.34.31937 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

c++.cpp

C:\temp>link c++.obj OS.lib /subsystem:console /out:c++.exe
Microsoft (R) Incremental Linker Version 14.34.31937.0
Copyright (C) Microsoft Corporation.  All rights reserved.


C:\temp>

 

  • They or their customers can then try to run the program and hope to get the following response:

 

C:\temp>c++.exe
os_int(&foo) returns 3

C:\temp>

 

See if you are able to repeat the above steps in yours and your students' environments.

 

If you can get this far, you effectively have resolved the issue.  You can then consider getting back to using Visual Studio solutions and projects to have a more user-friendly integrated development environment (IDE) that eases all the manual steps.

0 Kudos
JohnNichols
Valued Contributor III
2,105 Views

The Pros from Dover took over, I would follow their advice.  

 

0 Kudos
Olaf
Novice
1,962 Views

Dear friends,

 

yesterday I found the solution.

My dll use additional dll's not only from windows but from a third party developer. I saw it in the dependency walker. On my computer these third party dlls are no problem, but on the students computers they were on a wrong place. if the students copied them to this directory, where the exe of the main application is still placed, all problems had disappeared.

But thank you all for your help. With my reduced soure the problems were not included. Afterwards I know this.

 

Many thanks

 

Olaf from Austria

0 Kudos
FortranFan
Honored Contributor II
1,929 Views

@Olaf ,

Given your original post, "for years I programmed DLLs in FORTRAN in VS2017 and provided them to my students for using in an special application. Never there were any problems," it is really strange it took so much attention for you to realize, "On my computer these third party dlls are no problem, but on the students computers they were on a wrong place."

With your first post at comp.lang.fortran, you were immediately informed, "The problem is likely with inconsistent or missing libraries on your students' computer(s)."  Isn't that how it turned out?

Anyways, hope you have some takeaways from this sojourn online.  And I hope that will include an attempt to consider modern Fortran approaches, particularly if the consumption of such code by students is coming into play.

Assuming the students are all learning with their own or taxpayer funds, you may want to note in year 2023 they will be served better by not having to work with code such as the one you posted 

 

Function os_int(a)
!DEC$ ATTRIBUTES DLLEXPORT :: os_int
!DEC$ ATTRIBUTES STDCALL :: os_int
!   os_int - int
!   a      - int von a (int of this value will be calculated)
	IMPLICIT NONE
    double precision :: os_int, a
    os_int = int(a)
end function

 

that 

  1. may not have explicit interfaces
  2. may not be generally portable 

You can strive to show your students better illustrations of Fortran code now.  Many in industry would like to see students to graduate and come to work having seen much better in their college education.

0 Kudos
Olaf
Novice
1,912 Views

Hi Fortran-Fan,

 

thank you.

 

You are right, it could have gone better.

There are three problems (for my part):

First: Programming is not a part of the education of our degre. We educating the students about renewable energy. Most of the content is about technologies and applications of them. Calculations are normally done by using professional programs. I'm the only teacher who critizise that  and espacially that the student do not, whatthe programs are doing inside. The argument of my course director is that we are an university of  applied sciences and is not necessary for the students to know that, they need to apply technologies. I'm not agree, I did a lot of fights and I created a "loophole". So I use in bachelor theses works of the students (for wich I am the supervisor) a programm, where the students must model new applications.

https://www.simtechnology.com/cms/ipsepro-menu/ipse-pro

And that they are able to do this, I program some differnt units. And again in some of these units I need a different kind of programming, c++ or fortran can do. I myself studied a long time ago and I best program in fortran. Many years I had no problems exept this year (really strange). And I didn't knew what is the reason. Afer a while I asked you and yes I looked for missing dll's. But I had no idea which one and I thougt there can be different problems too. Only my enthusiasm makes this possible.

Secondly: I have not enough experience with programming

Thirdly: My English is not good enough to realize every subtlety and exact articulating. Exactly to formulate the problem, is not easy for me. Even in German I would have problems to explain my problem.

So, sorry for mistakes and thank you all for your support.

 

Olaf

 

Reply