给出一个简单的程序:
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hInstPrev,
LPSTR lpCmdLine, int nCmdShow)
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如果我运行g++ a.cpp,效果很好。
但是,运行g++ -c a.cpp && ar rcs a.a a.o && g++ a.a会出现以下错误:
c:/mingw32/bin/../lib/gcc/i686-w64-mingw32/4.8.1/../../../../i686-w64-mingw32/lib/../lib/libmingw32.a(lib32_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x39): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
为什么会发生这种情况的任何见解?如何仅将.a文件链接到程序?