i tried running the code below in local windows debugger and failed, but when i compile the source.cpp file using ctrl f7 it didn't. How to fix this

Trinh Nguyen Van 1 Reputation point
2021-07-10T11:19:27.26+00:00

113535-fail-at-debug.png

Developer technologies | C++
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. RLWA32 49,636 Reputation points
    2021-07-10T11:42:04.503+00:00

    It appears that your project is set as a console application but your code entry point is WinMain which is the entry point for a Windows GUI application. You can see that the linker error relates to an unresolved external symbol for _main which is the entry point for a console application. I'm guessing that you created an empty project and then added your code to it.

    Either create a Windows desktop application from the New Project templates or go into your existing project's property settings for the linker to /SUBSYSTEM:WINDOWS as shown here (make sure to change the setting for all platforms and all configurations)

    113500-subsystem.png

    If you really want a console application then change the code so that the entry point is main, not WinMain.

    1 person found this answer helpful.
    0 comments No comments

  2. Viorel 122.6K Reputation points
    2021-07-10T11:37:18.49+00:00

    Try experimenting with another kind of project: “Console App”. Then try “Windows Desktop Application”.

    0 comments No comments

  3. Jeanine Zhang-MSFT 11,356 Reputation points Microsoft External Staff
    2021-07-12T02:56:33.143+00:00

    Hi,

    ctrl+f7 is the keyboard shortcut for complie.

    "Building" is a vague term that usually means the entire process, preprocessing, compiling and linking.

    "Compiling" is the act of turning source code into object code.

    Compiling is just one of the steps in building. This is the reason why the following code fails to run in the local Windows debugger, but when use ctrl+f7 to compile the source.cpp file it works.

    For more details about the difference between Build and compile, I suggest you could refer to the link: https://stackoverflow.com/questions/15198725/build-or-compile

    The cause of the error lnk2019 is that the entry point is not defined. The application code must define an appropriate entry point: main or wmain for console applications, and WinMain or wWinMain for Windows applications.

    Best Regards,

    Jeanine


    If the response is helpful, please click "Accept Answer" and upvote it.

    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.


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.