언어/C,C++

[Win32] Visual Studio Win32 LNK2019 오류 해결

깜냥c 2023. 12. 28. 15:10

Visual Studio에서 빈 프로젝트를 만들고 Win32 콘솔 창을 띄우기 위해 다음과 같이 코드를 작성했다.

#include <windows.h>    // include the basic windows header file

// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nShowCmd)
{
    // create a "Hello World" message box using MessageBox()
    MessageBox(NULL,
        L"Hello World!",
        L"Just another Hello World program!",
        MB_ICONEXCLAMATION | MB_OK);

    // return 0 to Windows
    return 0;
}

 

 

그런데 빌드를 하니 아래처럼 LNK 2019 오류가 뜨며 실행이 안됐다.

 

 


 

나의 경우 해결 방법은 프로젝트 세팅에서 SubSystem을 CONSOLE에서 WINDOWS로 바꿔주면 됐다. 

 

Project - (프로젝트 네임) Properties
Linker - System - SubSystem
CONSOLE -> WINDOWS

 

 

적용 후 다시 실행하니 Win32 창이 잘 만들어졌다.

 

첫 Win32 프로그램

 

 

위 방법이 안 통하면 밑에 참고 링크에서 다른 해결법들을 찾아볼 수 있다.

 

참고 링크

더보기