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

Difficulties in obtaining .exe file from Fortran code in Visual Studio 2019

JSerra
Novice
3,843 Views

I am experiencing some difficulties in generating an .exe file from a Fortran 77 code. I am running VS Community 2019 on Windows 10. I installed the 'Intel Fortran Compiler (Beta) & Intel Fortran Compiler Classic'.

I am new to Fortran (and compiled languages), and I am a structural engineering, so please apologize some basic errors I might be doing.

The steps to reproduce my problem are as follows:
1) Launch VS and create new empty project on a local folder C:\Users\USER\Workspaces\Fortran
2) Project > Add New Item > Fortran Fixed-form File (.for), which creates Source1.for visible on the Solution Explorer under Source Files.
3) Copy+Paste sample code (it creates and populates a new file data1.dat with some data).
4) Ctrl+S > Build > Build Solution

The Build is successful but the data1.dat is not created and I cannot run Debug\Console1.exe (System Error: The code execution cannot proceed because libmmdd.dll was not found. Reinstalling the program may fix this problem).

Is this a matter of reinstalling VS (or the compiler?) or am I doing something wrong? Perhaps I did not download the right Intel product?

I attached a .zip with the project.

 

0 Kudos
1 Solution
JSerra
Novice
3,731 Views

Problem solved: in Project > Properties > Cinfig Properties > Fortran > Libraries > Runtime Library, I changed from Multithread DLL (/libs:dll /threads) to Debug Multithreaded (/libs:static /threads /dbglibs). Then the .exe file runs normally and generates the intended file.

I hope for my (basic) use of VS this does not have collateral effects.

EDIT: see @Steve_Lionel 's warning regarding side effects.

View solution in original post

0 Kudos
17 Replies
mecej4
Honored Contributor III
3,835 Views

The environment is probably not configured for Fortran. Try the following steps.

Open an Intel Fortran/OneAPi command window from the Windows Start menu. Enter the command "devenv" in that command window. Visual Studio will come up. Open your solution and you can do the steps of building, debugging, etc.

The EXE in your Zip ran normally and produced the data1.dat file.

0 Kudos
JSerra
Novice
3,827 Views

@mecej4 , aren't your steps equivalent to what I did in my question? I opened VS using the command prompt and did Build Solution, bu still the .exe file that appears in the Debug folder does not run.

How do I configure the environment for Fortran as you say?

0 Kudos
Steve_Lionel
Honored Contributor III
3,831 Views

Are you running the program from inside Visual Studio, or separately? Debug-configuration builds will not run outside the Visual Studio environment because the debug DLLs are not added to PATH.

0 Kudos
JSerra
Novice
3,825 Views

@Steve_Lionel if I understood your point, then no, I'm not running the .exe file from within VS (i.e., I'm double-clicking on the .exe file that is generated into the Debug folder once I press Build Solution). If this does not work, how can I generate an .exe file that can be invoked from other programs (my main program is written in Python and I want to call some Fortran 77 routines)?

0 Kudos
mecej4
Honored Contributor III
3,820 Views

JSerra wrote, "I'm double-clicking on the .exe file that is generated into the Debug folder once I press Build Solution".

That explains why things don't work. When you double click the icon of an EXE file, you are inheriting the default environment of any EXE on your system, and that one is probably not configured to run EXEs that depend on the Intel OneAPI runtime libraries.

You can (i) modify the system PATH (not recommended, has side effects that may be unexpected and undesirable), (ii) specify in Visual Studio that the path to the OneAPI RTL DLLs should be added to PATH, or (iii) run the EXE using the IFort command window.

0 Kudos
Steve_Lionel
Honored Contributor III
3,817 Views

The recommended solution is to build a Release configuration executable.  In your VS project, click on the Configuration option (highlighted) and change to Release. If you made any changes to project properties, you'll have to repeat them.

Screenshot 2021-07-02 115745.png

I don't recommend @mecej4 's suggestions. A Release configuration will use DLLs available through the system PATH environment variable.

0 Kudos
JSerra
Novice
3,790 Views

Even with the Release x64 option I cannot run the .exe file (same error pops-up). Am I doing steps 1-4 correctly (now selecting Release before building)? Is the type of project (Empty Project) correct?

0 Kudos
JSerra
Novice
3,774 Views

To use your option (ii), how do I find out where the DLLS are? I didn't get any .dll in my directory. 

Is the correct way adding PATH=%PATH%;$(ProjectDir)\some-framework\lib (ipsis verbis?) to Project > Properties > Conf Properties > Debugging > Environment as explained here ? (if so, it is still not working - I cannot run the .exe by double-clicking on it).

0 Kudos
Steve_Lionel
Honored Contributor III
3,769 Views

Are you sure it's the same error when you build in release mode? The one you showed before was for a debug DLL.

Please do not mess with PATH - that's unnecessary and possibly harmful.

0 Kudos
JSerra
Novice
3,765 Views

(PATH is now restored to default.)

I am doing steps 1-3 and step 4 is now:

4) Ctrl+S, select Release x64 (x86 is default not sure why), and then Build > Build Solution (do I need to Compile first?)

Then, a new folder named as "x64" appears within the project folder, containing Console1.exe. If I double-click on it, the same error (as when I was running the Debug option) pops up.

JSerra_0-1625324476422.png

 

0 Kudos
Steve_Lionel
Honored Contributor III
3,756 Views

It's not exactly the same error - note that the file name of the DLL is subtly different. The Debug configuration wanted libifcoremdd.dll, the release configuration is looking for libifcoremd.dll.

I suggest that you uninstall and reinstall the oneAPI HPC Toolkit. libifcoremd.dll (one d) should be installed in a common location that is added to PATH by the install. Before doing this you may want to log out of Windows and in again - sometimes I find that this fixes issues with new additions to PATH.

Build Solution does a compile if necessary. It's what you would normally use, rather than a separate Compile.

0 Kudos
jimdempseyatthecove
Honored Contributor III
3,760 Views

>>If I double-click on it...

That means: run the .exe using the environment variables currently in use by the Windows (File) Explorer. These setting are not necessarily the same environment variables as use (required) by the development system.

 

A "simple" hack you can do, assuming you want to use Windows (File) Explorer to launch your application is to first (sometime once per boot), is to launch the Intel Parallel Studio (or oneAPI) x64 command prompt, type in "explorer" (no quotes). This will a) set the environment variables for Intel development/runtime, b) launch Windows (file) Explorer with the proper environment.

Now you can browse and double click on your .exe(s).

Note, you can close the CMD window *** but I suggest you only minimize the Windows (file) Explorer for future use.

Also note, the Current Directory (and current Drive) are that of Windows (file) Explorer as launched and not (necessarily) that of the .exe.

There are similar methods to do this, you just have to be creative.

Jim Dempsey

0 Kudos
JSerra
Novice
3,732 Views

Problem solved: in Project > Properties > Cinfig Properties > Fortran > Libraries > Runtime Library, I changed from Multithread DLL (/libs:dll /threads) to Debug Multithreaded (/libs:static /threads /dbglibs). Then the .exe file runs normally and generates the intended file.

I hope for my (basic) use of VS this does not have collateral effects.

EDIT: see @Steve_Lionel 's warning regarding side effects.

0 Kudos
Steve_Lionel
Honored Contributor III
3,729 Views

Well, that is certainly one way to work around the issue, but I hope others reading this don't assume it is the best solution. You have something wrong with your installation and should repeat the install. There are several problems with this choice, including "baking in" to your EXE any bugs that may be in the support libraries, and making your EXEs much larger and consume more RAM than they would otherwise.

0 Kudos
JSerra
Novice
3,690 Views

I have reinstalled the Intel® Fortran Compiler Classic and Intel Fortran Compiler(Beta) (now running release 2021.3, before 2021.2) and followed your tip on restarting Windows. Still getting the same error(s).

Should I install the HPC Toolkit instead? (I was avoiding it due to its size on disk.) Is the libifcoremd.dll (one d) installed during the same installation or do I have to do it manually?

0 Kudos
Steve_Lionel
Honored Contributor III
3,664 Views

Oh, I forgot about this! You have to install the run-time DLLs separately. This is something Intel did in the oneAPI version that was never needed before.  Worse, Intel never tells you that this is necessary. Go to Intel® oneAPI standalone component installation files , select Runtime Versions > Windows > Intel Fortran Compiler Runtime for Windows.

OctavioDMA
Beginner
3,356 Views

Thank you very much for this information Steve. This completely solved my problem.

0 Kudos
Reply