IT

오류 LNK2019 : ___tmainCRTStartup 함수에서 참조 된 해결되지 않은 외부 기호 _WinMain @ 16

lottoking 2020. 6. 26. 07:49
반응형

오류 LNK2019 : ___tmainCRTStartup 함수에서 참조 된 해결되지 않은 외부 기호 _WinMain @ 16


아래와 같이 간단한 코드를 실행하는 동안 다음과 같은 두 가지 오류가 있습니다.

#include <iostream>
#include <string>
using namespace::std;

template <class Type>
class Stack
{
public:
    Stack (int max):stack(new Type[max]), top(-1), maxsize(max){}
    ~Stack (void) {delete []stack;}
    void Push (Type &val);
    void Pop (void) {if (top>=0) --top;}
    Type& Top (void) {return stack[top];}
    //friend ostream& operator<< (ostream&, Stack&);
private:
    Type *stack;
    int top;
    const int maxSize;
};

template <class Type>
void Stack <Type>:: Push (Type &val)
{
    if (top+1<maxsize)
        stack [++top]=val;
}

오류 :

MSVCRTD.lib (crtexew.obj) : 오류 LNK2019 : _WinMain@16함수에서 참조 된 확인할 수 없는 외부 기호___tmainCRTStartup

어떻게해야합니까?


링커 문제입니다.

Visual Studio에서 속성-> 링커-> 시스템-> 하위 시스템을 변경하십시오.

에서 윈도우 (/ SUBSYSTEM : WINDOWS)콘솔 (/ SUBSYSTEM : CONSOLE)

이것은 나를 도와


다른 사람들이 언급했듯이 하위 시스템을 콘솔로 변경할 수 있으며 오류가 사라집니다.

또는 Windows 하위 시스템을 유지하려면을 정의하지 않았으므로 진입 점을 암시 할 수 있습니다 ___tmainCRTStartup. 특성-> 링커-> 명령 행에 다음을 추가하여이를 수행 할 수 있습니다 .

/ ENTRY : "mainCRTStartup"

이렇게하면 콘솔 창을 제거 할 수 있습니다.


이 문제점이 있고 Qt를 사용중인 경우 qtmain.lib 또는 qtmaind.lib를 링크해야합니다.


다음 <tchar.h>줄을 포함하십시오 .

#define _tWinMain wWinMain

Console (/SUBSYSTEM:CONSOLE)다른 사람들이 말한 것처럼 변경하는 것 외에도 속성-> 링커-> 고급-> 진입 점 에서 진입 점 을 변경해야 할 수도 있습니다 . mainCRTStartup으로 설정하십시오 .

달리 지정하지 않으면 Visual Studio가 main 대신 WinMain 함수를 검색하는 것 같습니다.


유니 코드 문자 집합을 사용하지만 항목이 설정되지 않은 경우 / ENTRY를 지정할 수 있습니다. "wWinMainCRTStartup"


주요 기능이 보이지 않습니다.

주요 기능이 있는지 확인하십시오.

예 :

int main(int argc, TCHAR *argv[]){

}

그것이 잘 작동하기를 바랍니다. :)


프로젝트가 Dll이면 링커가 콘솔 프로그램을 빌드하려고 할 수 있습니다. 프로젝트 속성을여십시오. 일반 설정을 선택하십시오. 구성 유형 동적 라이브러리 (.dll)를 선택하십시오.


나는이 답변을 어디에 게시 해야할지 모르겠지만 그것이 올바른 장소라고 생각합니다. 오늘이 오류가 발생하여 하위 시스템을 전환해도 아무런 변화가 없었습니다.

64 비트 lib 파일을 32 비트 (x86)로 변경하면 속임수가 생겼습니다. 다른 사람을 도울 수 있기를 바랍니다!


If you actually want to use _tWinMain() instead of main() make sure your project relevant configuration have

  1. Linker-> System -> SubSystem => Windows(/SUBSYSTEM:WINDOWS)
  2. C/C++ -> Preprocessor -> Preprocessor Definitions => Replace _CONSOLE with _WINDOWS
  3. In the c/cpp file where _tWinMain() is defined, add:

    #include <Windows.h> #include <tchar.h>


Your tried to turn that source file into an executable, which obviously isn't possible, because the mandatory entry point, the main function, isn't defined. Add a file main.cpp and define a main function. If you're working on the commandline (which I doubt), you can add /c to only compile and not link. This will produce an object file only, which needs to be linked into either a static or shared lib or an application (in which case you'll need an oject file with main defined).

_WinMain is Microsoft's name for main when linking.

Also: you're not running the code yet, you are compiling (and linking) it. C++ is not an interpreted language.


If you are using CMake, you can also get this error when you set SET(GUI_TYPE WIN32) on a console application.


The erudite suggestions mentioned above will solve the problem in 99.99% of the cases. It was my luck that they did not. In my case it turned out I was including a header file from a different Windows project. Sure enough, at the very bottom of that file I found the directive:

#pragma comment(linker, "/subsystem:Windows")

Needless to say, removing this line solved my problem.

참고URL : https://stackoverflow.com/questions/6626397/error-lnk2019-unresolved-external-symbol-winmain16-referenced-in-function

반응형