zhr811022 发表于 2011-12-20 09:47

vc下udp编译程序一,问题描述

<DIV>c中error LNK2001:unresolved external symbol <a href="mailto:_WinMain@16" target="_blank">_WinMain@16</A>的解决方法(转)一,问题描述<BR>error LNK2001: unresolved external symbol <a href="mailto:_WinMain@16" target="_blank">_WinMain@16</A><BR>debug/main.exe:fatal error LNK 1120:1 unresolved externals <BR>error executing link.exe;</DIV>
<DIV>二,产生这个问题可能的原因<BR>1, 你用vc建了一个控制台程序,它的入口函数应该是main, 而你使用了WinMain.</DIV>
<DIV>2.&nbsp; 你用vc打开了一个.c/.cpp 文件,然后直接编译这个文件,这个文件中使用了WinMian而不是main作为入口函数。vc这时的默认设置是针对控制台程序的。</DIV>
<DIV>三, 解决方法<BR>1.进入project-&gt;setting-&gt;c/c++, 在category中选择preprocessor,在processor definitions中删除_CONSOLE, 添加_WINDOWS</DIV>
<DIV>2.进入project-&gt;setting-&gt;Link, 在Project options中将 /subsystem:console改为/subsystem:windows.</DIV>
<DIV>3.保存设置,Rebuild All.</DIV>
<DIV>VS2005中的设置请参考对应项进行设置</DIV>
<DIV>四,VS2005中的设置</DIV>
<DIV>1.菜单中选择 Project-&gt;Properties, 弹出Property Pages窗口</DIV>
<DIV>2.在左边栏中依次选择:Configuration Properties-&gt;C/C++-&gt;Preprocessor,然后在右边栏的Preprocessor Definitions对应的项中删除_CONSOLE, 添加_WINDOWS.</DIV>
<DIV>3.在左边栏中依次选择:Configuration Properties-&gt;Linker-&gt;System,然后在右边栏的SubSystem对应的项改为Windows(/SUBSYSTEM:WINDOWS)</DIV>
<DIV>4.Rebuild All. Ok ?</DIV>
<DIV>测试:(环境:vs2005,编程语言vc)</DIV>
<DIV>1.用文本编辑器编写如下代码:</DIV>
<DIV>// test.c<BR>#i nclude &lt;windows.h&gt;</DIV>
<DIV>int APIENTRY WinMain(HINSTANCE hInstance,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HINSTANCE hPrevInstance,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LPSTR&nbsp;&nbsp;&nbsp;&nbsp; lpCmdLine,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nCmdShow)<BR>{<BR>&nbsp;MessageBox(NULL, "Hello!", "title", MB_OK);<BR>}</DIV>
<DIV>假设把文件包存为test.c.</DIV>
<DIV>2.用vs2005建一个Win32 Console Application, 注意在Application Settings设置为Empty project. 然后把test.c添加到工程中去。</DIV>
<DIV>3.vs2005建立的工程默认是支持UNICODE的,我不用这个,所以在菜单中选择 Project-&gt;Properties, 弹出Property Pages窗口。在左边栏中依次选择:Configuration Properties-&gt;General,然后把右边栏的Character Set 改为Use Multi-Byte Character Set.</DIV>
<DIV>4.编译,出现如下错误:<BR>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup<BR>C:\test\Debug\test.exe : fatal error LNK1120: 1 unresolved externals</DIV>
<DIV>5.按照上述VS2005中的设置方法进行设置,然后再编译,错误消失了吧! </DIV>
<DIV>(Update:2006-10-28添加第四部分)</DIV>
页: [1]
查看完整版本: vc下udp编译程序一,问题描述