error LNK2019: 无法解析的外部符号 _main
的有关信息介绍如下:1>------ 已启动生成: 项目: Beizer, 配置: Debug Win32 ------
1> interpolation.cpp
1>h:\2 study\2 专业\3 计算机\2 导师\4 task\求根问题\beizer\beizer\interpolation.cpp(5): warning C4081: 应输入“标识符”;找到“(”
1>h:\2 study\2 专业\3 计算机\2 导师\4 task\求根问题\beizer\beizer\interpolation.cpp(71): warning C4244: “参数”: 从“time_t”转换到“unsigned int”,可能丢失数据
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: 无法解析的外部符号 _main,该符号在函数 ___tmainCRTStartup 中被引用
1>H:\2 study\2 专业\3 计算机\2 导师\4 Task\求根问题\Beizer\Debug\Beizer.exe : fatal error LNK1120: 1 个无法解析的外部命令
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
测试代码如下(代码来源于网络):
#include
#include
#include
#define NUM 10
#pragma(lib, "MSVCRTD.lib");
LRESULT CALLBACK Winproc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstanc, LPSTR lpCmdLine, int nShowCmd)
{
MSG msg;
static TCHAR szClassName[] = TEXT("::Bezier样条计算公式由法国雷诺汽车公司的工程师Pierm Bezier于六十年代提出");
HWND hwnd;
WNDCLASS wc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hInstance = hInstance;
wc.lpfnWndProc = Winproc;
wc.lpszClassName = szClassName;
wc.lpszMenuName = NULL;
wc.style = CS_HREDRAW | CS_VREDRAW;
if (!RegisterClass(&wc))
{
MessageBox(NULL, TEXT("注册失败"), TEXT("警告框"), MB_ICONERROR);
return 0;
}
hwnd = CreateWindow(szClassName, szClassName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, SW_SHOWMAXIMIZED);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK Winproc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
HDC hdc;
static POINT pt[NUM];
TEXTMETRIC tm;
static int cxClient, cyClient;
HPEN hpen;
int i, j, k, n, t;
switch (message)
{
case WM_CREATE:
static int cxchar;
hdc = GetDC(hwnd);
GetTextMetrics(hdc, &tm);
cxchar = tm.tmAveCharWidth;
ReleaseDC(hwnd, hdc);
case WM_SIZE:
cxClient = LOWORD(lparam);
cyClient = HIWORD(lparam);
return 0;
case WM_PAINT:
hdc = GetDC(hwnd);
srand(time(0));
Rectangle(hdc, 0, 0, cxClient, cyClient);
for (i = 0; i < 5; i++)
{
SelectObject(hdc, GetStockObject(WHITE_PEN));
PolyBezier(hdc, pt, NUM);
for (j = 0; j < NUM; j++)
{
pt[j].x = rand() % cxClient;
pt[j].y = rand() % cyClient;
}
hpen = CreatePen(PS_INSIDEFRAME, 3, RGB(rand() % 256, rand() % 256, rand() % 256));
DeleteObject(SelectObject(hdc, hpen));
PolyBezier(hdc, pt, NUM);
for (k = 0; k < 50000000; k++);
}
for (i = 0; i < 100; i++)
{
Ellipse(hdc, rand() % cxClient, rand() % cyClient, rand() % cxClient, rand() % cyClient);
Pie(hdc, j = rand() % cxClient, k = rand() % cyClient, n = rand() % cxClient, t = rand() % cyClient, rand() % cxClient, rand() % cyClient, rand() % cxClient, rand() % cyClient);
}
if ((n = (n + j) / 2) > cxchar * 20) n = cxchar * 20;
SetTextColor(hdc, RGB(rand() % 256, rand() % 256, rand() % 256));
ReleaseDC(hwnd, hdc);
DeleteObject(hpen);
ValidateRect(hwnd, NULL);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wparam, lparam);
}
编译时出现如下错误:
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: 无法解析的外部符号 _main,该符号在函数 ___tmainCRTStartup 中被引用
右击项目,打开“属性”页
更改上图红色框内容为/subsystem:windows。如果是刚开始默认的是/subsystem:windows
则改为/subsytem:console
再次编译即过通过测试,运行结果截图如下