How to compile a code for Windows GUI application using cl command?

Arda Şenyürek 20 Reputation points
2023-08-03T12:48:03.05+00:00

I would like to run the tutorial called Module 1. Your First Windows Program without using Visual Studio Code. I'd like to use vim for it. I installed the Visual Studio, and run the basic code on the official page.

However, when I want to compile a code that simply creates a window, it gives LNK2019 errors for "__imp_CreateWindowExW, __imp_ShowWindow", and others. In the end, it gives "x.exe: fatal error LNK1120: 11 unresolved externals".

I try to compile my x.cpp file using "cl /EHsc /ZW x.cpp /link" command in the x64 Native Command Prompt.

This is my first time asking here, if there is any mistake in my question sorry for it. I am looking forward to provide further information if needed, Thanks.

Windows for business | Windows Client for IT Pros | User experience | Other
Developer technologies | C++
{count} votes

Accepted answer
  1. Minxin Yu 13,501 Reputation points Microsoft External Staff
    2023-08-04T02:13:22.46+00:00

    Hi,Arda Şenyürek

    /ZW is used for UWP projects, not required for Win32 projects.
    https://learn.microsoft.com/en-us/cpp/build/reference/zw-windows-runtime-compilation?view=msvc-170

    But the exe was created successfully. You should be able to find x.exe in the current directory.
    User's image

    Best regards,

    Minxin Yu


    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.


1 additional answer

Sort by: Most helpful
  1. Arda Şenyürek 20 Reputation points
    2023-08-03T13:01:20.11+00:00

    Check if the errors decrease after adding some library files: cl /EHsc /ZW x.cpp /link user32.lib kernel32.lib.

    it certainly did. Now it only gives me

    dllmain.cpp(16): warning C4447: 'main' signature found without threading mode
    l. Consider using 'int main(Platform::Array<Platform::String^>^ args)'.
    Microsoft (R) Incremental Linker Version 14.36.32537.0
    Copyright (C) Microsoft Corporation.  All rights reserved.
    /winmd
    /out:x.exe
    user32.lib
    kernel32.lib
    x.obj
    c:\hello>
    

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.