`WinMain @ 16 '에 대한 정의되지 않은 참조
를 사용하여 프로그램을 빌드하려고 Eclipse CDT
하면 다음과 같은 결과가 나타납니다.
/mingw/lib/libmingw32.a(main.o):main.c:(.text+0x106) :`WinMain @ 16에 대한 정의되지 않은 참조
왜 그런 겁니까? 그리고이 문제를 어떻게 해결할 수 있습니까?
다음 Windows API 수준 프로그램을 고려하십시오.
#define NOMINMAX
#include <windows.h>
int main()
{
MessageBox( 0, "Blah blah...", "My Windows app!", MB_SETFOREGROUND );
}
이제 특별한 옵션없이 GNU 도구 모음 (예 : g ++)을 사용하여 빌드 해 보겠습니다. 여기 gnuc
에 제가 사용하는 배치 파일이 있습니다. g ++를 더 표준으로 만드는 옵션 만 제공합니다.
C : \ test> gnuc x.cpp C : \ test> objdump -x a.exe | findstr / i "^ 하위 시스템" 하위 시스템 00000003 (Windows CUI) C : \ 테스트> _
이는 링커가 기본적으로 콘솔 하위 시스템 실행 파일을 생성했음을 의미합니다 . 파일 헤더 의 하위 시스템 값은 프로그램에 필요한 서비스를 Windows에 알려줍니다. 이 경우 콘솔 시스템에서는 프로그램에 콘솔 창이 필요합니다.
이것은 또한 명령 인터프리터가 프로그램이 완료 될 때까지 기다리게합니다.
이제 GUI 하위 시스템으로 빌드 해 보겠습니다 . 이는 프로그램에 콘솔 창이 필요하지 않음을 의미합니다.
C : \ test> gnuc x.cpp -mwindows C : \ test> objdump -x a.exe | findstr / i "^ 하위 시스템" 하위 시스템 00000002 (Windows GUI) C : \ 테스트> _
-mwindows
플래그가 반 문서화 되었지만 지금까지는 괜찮습니다 .
반 문서화 된 플래그없이 빌드하려면 링커에게 원하는 하위 시스템 값을 더 구체적으로 알려야하며 일부 Windows API 가져 오기 라이브러리는 일반적으로 명시 적으로 지정해야합니다.
C : \ test> gnuc x.cpp -Wl, -subsystem, windows C : \ test> objdump -x a.exe | findstr / i "^ 하위 시스템" 하위 시스템 00000002 (Windows GUI) C : \ 테스트> _
GNU 툴체인에서는 잘 작동했습니다.
그러나 Microsoft 도구 체인, 즉 Visual C ++는 어떻습니까?
음, 콘솔 하위 시스템 실행 파일로 빌드하면 잘 작동합니다.
C : \ test> msvc x.cpp user32.lib x.cpp C : \ test> dumpbin / headers x.exe | / i "서브 시스템"찾기 | / i "Windows"찾기 3 하위 시스템 (Windows CUI) C : \ 테스트> _
그러나 Microsoft의 도구 모음을 GUI 하위 시스템으로 구축하면 기본적으로 작동하지 않습니다.
C : \ test> msvc x.cpp user32.lib / link / subsystem : windows x.cpp LIBCMT.lib (wincrt0.obj) : 오류 LNK2019 : ___tmainCRTStartu 함수에서 참조 된 해결되지 않은 외부 기호 _WinMain @ 16 피 x.exe : 치명적인 오류 LNK1120 : 해결되지 않은 외부 1 개 C : \ 테스트> _
기술적으로 이것은 Microsoft의 링커 가 GUI 하위 시스템에 대해 기본적으로 비표준 이기 때문 입니다. 기본적으로 하위 시스템이 GUI 인 경우 Microsoft의 링커는 표준 대신 Microsoft의 비표준을 호출 하는 기계 코드 실행이 시작되는 함수 인 런타임 라이브러리 진입 점을 사용합니다 .winMainCRTStartup
WinMain
main
그러나 그것을 고치는 데 큰 문제는 없습니다.
당신이해야 할 일은 마이크로 소프트 링커에게 어떤 진입 점을 사용할 mainCRTStartup
것인지 , 즉 표준을 호출 하는를 알려주 는 것입니다 main
.
C:\test> msvc x.cpp user32.lib /link /subsystem:windows /entry:mainCRTStartup x.cpp C:\test> dumpbin /headers x.exe | find /i "subsystem" | find /i "Windows" 2 subsystem (Windows GUI) C:\test> _
No problem, but very tedious. And so arcane and hidden that most Windows programmers, who mostly only use Microsoft’s non-standard-by-default tools, do not even know about it, and mistakenly think that a Windows GUI subsystem program “must” have non-standard WinMain
instead of standard main
. In passing, with C++0x Microsoft will have a problem with this, since the compiler must then advertize whether it's free-standing or hosted (when hosted it must support standard main
).
Anyway, that's the reason why g++ can complain about WinMain
missing: it's a silly non-standard startup function that Microsoft's tools require by default for GUI subsystem programs.
But as you can see above, g++ has no problem with standard main
even for a GUI subsystem program.
So what could be the problem?
Well, you are probably missing a main
. And you probably have no (proper) WinMain
either! And then g++, after having searched for main
(no such), and for Microsoft's non-standard WinMain
(no such), reports that the latter is missing.
Testing with an empty source:
C:\test> type nul >y.cpp C:\test> gnuc y.cpp -mwindows c:/program files/mingw/bin/../lib/gcc/mingw32/4.4.1/../../../libmingw32.a(main.o):main.c:(.text+0xd2): undefined referen ce to `WinMain@16' collect2: ld returned 1 exit status C:\test> _
To summarize the above post by Cheers and hth. - Alf, Make sure you have main()
or WinMain()
defined and g++ should do the right thing.
My problem was that main()
was defined inside of a namespace by accident.
I was encountering this error while compiling my application with SDL. This was caused by SDL defining it's own main function in SDL_main.h. To prevent SDL define the main function an SDL_MAIN_HANDLED macro has to be defined before the SDL.h header is included.
Try saving your .c file before building. I believe your computer is referencing a path to a file with no information inside of it.
--Had similar issue when building C projects
참고URL : https://stackoverflow.com/questions/5259714/undefined-reference-to-winmain16
'Programming' 카테고리의 다른 글
Swift make 메서드 매개 변수를 변경할 수 있습니까? (0) | 2020.08.15 |
---|---|
Core 2.0의 ConfigurationBuilder에서 BasePath를 설정하는 방법 (0) | 2020.08.15 |
SQLAlchemy ORM을 사용하여 효율적으로 데이터베이스 업데이트 (0) | 2020.08.15 |
'async void'이벤트 핸들러를 피해야합니까? (0) | 2020.08.14 |
노드 모듈에서 멋진 글꼴 아이콘을 사용하는 방법 (0) | 2020.08.14 |