Help with Compiling Fortran 77 Code in Visual Studio with Intel OneAPI

Hi everyone,

I’m currently working on a Fortran project that includes some Fortran 77 code (.f files). I’ve been able to compile this code successfully using gfortran with the -std=legacy flag. However, I’m now using MS Visual Studio 2022 with the Intel OneAPI compiler, and I’m trying to figure out how to set it up to compile these specific .f files with the -std=legacy option.

The rest of my project contains modern Fortran code that doesn’t require this legacy option, so ideally, I’d like to apply the -std=legacy flag only to the relevant files.

I tried adding -std=legacy in the “Additional Options” under “Command line” but that didn’t seem to work. Does anyone have suggestions on how to properly configure Visual Studio to achieve this?

1 Like

As you are using VS, you should encapsulate your legacy code in a dedicated project (vfproj) and reference it in another project with your modern code.
VS should then recognize from the extension that it’s dealing with fixed form Fortran. If not you can right click on the project and go to properties. You should be able to specify the form and the standard to enforce.

1 Like

I also noticed that adding options in the command line field does not seem to work. Some time ago I had added -fast but it did not work

Hi @davidpfister,

Thank you for your suggestion. I followed your advice and separated my project into two parts, with one specifically for the legacy code. I configured the project settings to use fixed form. However, I am encountering compilation errors in the Visual Studio IDE, even though the .f file compiles successfully using the ifort command line with the -std=legacy flag.

To troubleshoot, I tested other fixed-form codes from Netlib, such as dlsode.f, which compiled successfully in both the VS IDE and the command line (with and without the -std=legacy flag). This leads me to believe that Visual Studio may not fully recognize the legacy code. I also adjusted the compatibility settings in the project properties (see attached screenshots), but the errors persist.

Are there any additional settings I might have overlooked in the Visual Studio IDE?

Thanks!

Which error did you get?
So I take it that the vfproj containing daskr compiles fine, and you have issues when referencing it into another project, right? What’s the build log saying?

1 Like

I can successfully compile the legacy code using ifort with the -std=legacy flag via the command line. However, in the Visual Studio IDE, I haven’t been able to apply this flag successfully. I tried adding it in the command line options within the project settings, but it didn’t work. Instead, I’ve been trying to find a similar option in the project or file properties, but the code still fails to compile in the IDE.

1 Like

Here is my vfproj. It only include daux.f, ddaspk.f and dlinpk.f (just replace ddaskr). With this it compiles fine with ifort 21 and VS 2019. I have no specific options, VS manages everything based on the extensions.

If you want to build from the command line using the vfproj you can use the following: devenv ddaspk.vfproj /Rebuild Release|x64

<?xml version="1.0" encoding="UTF-8"?>
<VisualStudioProject ProjectCreator="Intel Fortran" Keyword="Console Application" Version="11.0" ProjectIdGuid="{462EEAB7-423B-4E25-87CD-2296D84DF8CF}">
	<Platforms>
		<Platform Name="Win32"/>
		<Platform Name="x64"/></Platforms>
	<Configurations>
		<Configuration Name="Debug|Win32" OutputDirectory="bin\$(ConfigurationName)\$(PlatformName)" IntermediateDirectory="obj\$(ConfigurationName)\$(PlatformName)" ConfigurationType="typeStaticLibrary">
				<Tool Name="VFFortranCompilerTool" SuppressStartupBanner="true" DebugInformationFormat="debugEnabled" Optimization="optimizeDisabled" Preprocess="preprocessYes" PreprocessorDefinitions="DEBUG" WarnInterfaces="true" Traceback="true" BoundsCheck="true" StackFrameCheck="true" RuntimeLibrary="rtMultiThreadedDebugDLL"/>
				<Tool Name="VFLinkerTool" LinkIncremental="linkIncrementalNo" SuppressStartupBanner="true" GenerateDebugInformation="true"/>
				<Tool Name="VFLibrarianTool"/>
				<Tool Name="VFResourceCompilerTool"/>
				<Tool Name="VFMidlTool" SuppressStartupBanner="true"/>
				<Tool Name="VFCustomBuildTool"/>
				<Tool Name="VFPreLinkEventTool"/>
				<Tool Name="VFPreBuildEventTool"/>
				<Tool Name="VFPostBuildEventTool"/>
				<Tool Name="VFManifestTool" SuppressStartupBanner="true"/></Configuration>
		<Configuration Name="Debug|x64" OutputDirectory="bin\$(ConfigurationName)\$(PlatformName)" IntermediateDirectory="obj\$(ConfigurationName)\$(PlatformName)" ConfigurationType="typeStaticLibrary">
				<Tool Name="VFFortranCompilerTool" SuppressStartupBanner="true" DebugInformationFormat="debugEnabled" Optimization="optimizeDisabled" Preprocess="preprocessYes" PreprocessorDefinitions="DEBUG" WarnInterfaces="true" Traceback="true" BoundsCheck="true" StackFrameCheck="true" RuntimeLibrary="rtMultiThreadedDebugDLL"/>
				<Tool Name="VFLinkerTool" LinkIncremental="linkIncrementalNo" SuppressStartupBanner="true" GenerateDebugInformation="true"/>
				<Tool Name="VFLibrarianTool"/>
				<Tool Name="VFResourceCompilerTool"/>
				<Tool Name="VFMidlTool" SuppressStartupBanner="true" TargetEnvironment="midlTargetAMD64"/>
				<Tool Name="VFCustomBuildTool"/>
				<Tool Name="VFPreLinkEventTool"/>
				<Tool Name="VFPreBuildEventTool"/>
				<Tool Name="VFPostBuildEventTool"/>
				<Tool Name="VFManifestTool" SuppressStartupBanner="true"/></Configuration>
		<Configuration Name="Release|Win32" OutputDirectory="bin\$(ConfigurationName)\$(PlatformName)" IntermediateDirectory="obj\$(ConfigurationName)\$(PlatformName)" ConfigurationType="typeStaticLibrary">
				<Tool Name="VFFortranCompilerTool" SuppressStartupBanner="true" Preprocess="preprocessYes" RuntimeLibrary="rtMultiThreadedDLL"/>
				<Tool Name="VFLinkerTool" LinkIncremental="linkIncrementalNo" SuppressStartupBanner="true"/>
				<Tool Name="VFLibrarianTool"/>
				<Tool Name="VFResourceCompilerTool"/>
				<Tool Name="VFMidlTool" SuppressStartupBanner="true"/>
				<Tool Name="VFCustomBuildTool"/>
				<Tool Name="VFPreLinkEventTool"/>
				<Tool Name="VFPreBuildEventTool"/>
				<Tool Name="VFPostBuildEventTool"/>
				<Tool Name="VFManifestTool" SuppressStartupBanner="true"/></Configuration>
		<Configuration Name="Release|x64" OutputDirectory="bin\$(ConfigurationName)\$(PlatformName)" IntermediateDirectory="obj\$(ConfigurationName)\$(PlatformName)" ConfigurationType="typeStaticLibrary">
				<Tool Name="VFFortranCompilerTool" SuppressStartupBanner="true" Preprocess="preprocessYes" RuntimeLibrary="rtMultiThreadedDLL"/>
				<Tool Name="VFLinkerTool" LinkIncremental="linkIncrementalNo" SuppressStartupBanner="true"/>
				<Tool Name="VFLibrarianTool"/>
				<Tool Name="VFResourceCompilerTool"/>
				<Tool Name="VFMidlTool" SuppressStartupBanner="true" TargetEnvironment="midlTargetAMD64"/>
				<Tool Name="VFCustomBuildTool"/>
				<Tool Name="VFPreLinkEventTool"/>
				<Tool Name="VFPreBuildEventTool"/>
				<Tool Name="VFPostBuildEventTool"/>
				<Tool Name="VFManifestTool" SuppressStartupBanner="true"/></Configuration></Configurations>
	<Files>
		<File RelativePath=".\daux.f"/>
		<File RelativePath=".\ddaspk.f"/>
		<File RelativePath=".\dlinpk.f"/></Files>
	<Globals/></VisualStudioProject>