HelloWorld program does not compile on Visual Studio (Fortran)

lauras8306 0 Reputation points
2023-06-07T18:46:07.89+00:00

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

Developer technologies Visual Studio Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Tianyu Sun-MSFT 34,436 Reputation points Microsoft External Staff
    2023-06-08T09:39:12.5333333+00:00

    Hello @lauras8306 ,

    Welcome to Microsoft Q&A forum.

    I guess you selected the Empty Project for creating an application with a Windows user interface, if you choose the Empty Project for creating a command-line application, this issue may not appear.

    User's image

    Anyways, please right-click your project > Properties > Configuration Properties > Linker > System > SubSystem > try to select Console (/SUBSYSTEM:CONSOLE) > then rebuild your project.

    Feel free to let us know the results.

    Sincerely,

    Tianyu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. lauras8306 0 Reputation points
    2023-06-09T13:55:08.3666667+00:00

    hi! Thanks for the answer!

    Not sure if that is equivalent, but I solved it by selecting a Console Project instead of an Empty Project as format when creating the project.

    Cheers,

    Laura


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.