读书人

弱问一个LNK2001异常高手请支招

发布时间: 2012-03-11 18:15:39 作者: rapoo

弱问一个LNK2001错误,高手请支招
我在win32 Application下建立了一个nice 的工程
有3个文件
f1.cpp
#include <iostream>
#include "coordin.h "
using namespace std;
int main ()
{
rect rplace;
polar pplace;

cout < < "Enter the x and y values: ";
while (cin > > rplace.x> > rplace.y)
{
pplace = rect_to_polar (rplace);
show_polar(pplace);
cout < < "Next two number (q to quit): ";
}
cout < < "Bye!\n ";
return 0;
}

f2.cpp
#include <iostream>
#include <cmath>
#include "coordin.h "


polar rect_to_polar (rect xypos)
{
using namespace std;
polar answer;
answer.distance =
sqrt (xypos.x*xypos.y + xypos.y*xypos.y);
answer.angle = atan2(xypos.y ,xypos.x);
return answer;
}

void show_polar (polar dapos)
{using namespace std;
const double rad = 57.29577951;

cout < < "distance = " < <dapos.distance;
cout < < ", angle = " < <dapos.angle*rad;
cout < < " degrees\n ";
}

coordin.h

#ifndef COORDIN_H_
#define COORDIN_H_
struct polar
{
double distance;
double angle;
};

struct rect
{
double x;
double y;
};

polar rect_to_polar (rect xypos);
void show_polar (polar dapos);

#endif


编译后出先LINK2001错误
error LNK2001: unresolved external symbol _WinMain@16

于是 我把函数入口改为
int WinMain ()
编译以后又有错误
warning C4007: 'WinMain ' : must be '__stdcall '

查资料 了解到 必要要函数调用约定
于是。。
int WINAPI WinMain ()
编译后还是
error C2146: syntax error : missing '; ' before identifier 'WinMain '
到这里我就完全不知道怎么办了

请高手们帮我改一下 顺便解释一下为什么会出现这个错误?

[解决办法]
修改链接选项,将subsystem改为console
[解决办法]
工程建错了, 要建立Win32 console application
[解决办法]
......Linker---> System---> SubSystem: Console
[解决办法]
看来是第一次用VC啊. 一和三楼方法对楼主可能复杂了点,按2楼重建工程好了.

读书人网 >C++

热点推荐