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

unable to compile helloWorld program (Fortran, empty project)

lauras8306
Beginner
684 Views

Hi! I just installed Microsoft Visual Studio Community 2022 (64 bit) - version 17.6.2 and the oneAPI HPC Toolkit on a Windows 10 machine.

 

I created a new Fortran Empty Project test_fortran.vfproj, which also created the solution test_fortran.sln
I then added as a source file the file main.f90, which reads:


program main
      print *, 'Hello, World!'
end program main

 


I tried to compile the solution, but I get the following error:

File MSVCRTD.lib(exe_winmain.obj): error LNK2019: reference to the external symbol WinMain not resolved in the function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)

File test_fortran.exe: fatal error LNK1120: 1 external not resolved

 

 

What should I do to solve this? Thanks a lot in advance,

Laura

1 Solution
jimdempseyatthecove
Honored Contributor III
670 Views

Intel Fortran (both ifx and ifort) require Microsoft Visual Studio C/C++ tools to be installed. 

I do note the linker was found, so you likely have installed C/C++

 

WinMain is an entrypoint used by Windows application.

The program you posted is a console program. Select console application from the MS VS template for specifying program type.

Jim Dempsey

View solution in original post

4 Replies
jimdempseyatthecove
Honored Contributor III
671 Views

Intel Fortran (both ifx and ifort) require Microsoft Visual Studio C/C++ tools to be installed. 

I do note the linker was found, so you likely have installed C/C++

 

WinMain is an entrypoint used by Windows application.

The program you posted is a console program. Select console application from the MS VS template for specifying program type.

Jim Dempsey

MWind2
New Contributor III
661 Views

I am using VS 2022 17.4.4 and 2023.1 ifort/ifx compilers and got no errors. I selected "Fortran empy project" and added Source1.f90 and it compiled on both ifort and ifx compilers. Do you have "Desktop development with c++" installed?

I now see @jimdempseyatthecove previously mentioned the desktop feature.

0 Kudos
Steve_Lionel
Honored Contributor III
651 Views

The error mentioned by @lauras8306  is, as Jim suggested, triggered by selecting an inappropriate project type when creating the project. This can be a confusing thing. As Jim said, selecting a project type with the Console tag (there are several) is key when you have a traditional Fortran program. What happened instead is that a "Desktop" project was selected, which wants a WinMain entry point and code that uses the Windows API to create windows. (The exception to this is QuickWin, which would also work here but is probably not what was wanted.)

 

There are two Empty Project templates, one for Console and one for Desktop. Be sure to select the correct one.

lauras8306
Beginner
634 Views

using Console solved the issue. Thanks a lot!

Reply