Jian's profile永不放弃BlogLists Tools Help

Blog


May 28

error LNK2001

 在创建MFC项目时,   不使用MFC   AppWizard向导,   如果没有设置好项目参数,   就会在编译时产生很多连接错误,   如error   LNK2001错误,   典型的错误提示有:  
  libcmtd.lib(crt0.obj)   :   error   LNK2001:   unresolved   external   symbol   _main  
  LIBCD.lib(wincrt0.obj)   :   error   LNK2001:   unresolved   external   symbol   _WinMain@16  
  msvcrtd.lib(crtexew.obj)   :   error   LNK2001:   unresolved   external   symbol   _WinMain@16  
  nafxcwd.lib(thrdcore.obj)   :   error   LNK2001:   unresolved   external   symbol   __beginthreadex  
  nafxcwd.lib(thrdcore.obj)   :   error   LNK2001:   unresolved   external   symbol   __endthreadex  
  下面介绍解决的方法:  
  1.   Windows子系统设置错误,   提示:  
  libcmtd.lib(crt0.obj)   :   error   LNK2001:   unresolved   external   symbol   _main  
  Windows项目要使用Windows子系统,   而不是Console,   可以这样设置:  
  [Project]   -->   [Settings]   -->   选择"Link"属性页,  
  在Project   Options中将/subsystem:console改成/subsystem:windows    
  2.   Console子系统设置错误,   提示:  
  LIBCD.lib(wincrt0.obj)   :   error   LNK2001:   unresolved   external   symbol   _WinMain@16  
  控制台项目要使用Console子系统,   而不是Windows,   设置:  
  [Project]   -->   [Settings]   -->   选择"Link"属性页,  
  在Project   Options中将/subsystem:windows改成/subsystem:console  
  3.   程序入口设置错误,   提示:  
  msvcrtd.lib(crtexew.obj)   :   error   LNK2001:   unresolved   external   symbol   _WinMain@16  
  通常,   MFC项目的程序入口函数是WinMain,   如果编译项目的Unicode版本,   程序入口必须改为wWinMainCRTStartup,   所以需要重新设置程序入口:  
  [Project]   -->   [Settings]   -->   选择"C/C++"属性页,  
  在Category中选择Output,  
  再在Entry-point   symbol中填入wWinMainCRTStartup,   即可  
  4.   线程运行时库设置错误,   提示:  
  nafxcwd.lib(thrdcore.obj)   :   error   LNK2001:   unresolved   external   symbol   __beginthreadex  
  nafxcwd.lib(thrdcore.obj)   :   error   LNK2001:   unresolved   external   symbol   __endthreadex  
  这是因为MFC要使用多线程时库,   需要更改设置:  
  [Project]   -->   [Settings]   -->   选择"C/C++"属性页,  
  在Category中选择Code   Generation,  
  再在Use   run-time   library中选择Debug   Multithreaded或者multithreaded  
  其中,  
  Single-Threaded                                 单线程静态链接库(release版本)  
  Multithreaded                                     多线程静态链接库(release版本)  
  multithreaded   DLL                             多线程动态链接库(release版本)  
  Debug   Single-Threaded                     单线程静态链接库(debug版本)  
  Debug   Multithreaded                         多线程静态链接库(debug版本)  
  Debug   Multithreaded   DLL                 多线程动态链接库(debug版本)  
  单线程:   不需要多线程调用时,   多用在DOS环境下  
  多线程:   可以并发运行  
  静态库:   直接将库与程序Link,   可以脱离MFC库运行  
  动态库:   需要相应的DLL动态库,   程序才能运行  
  release版本:   正式发布时使用  
  debug版本:   调试阶段使用  

Comments

Please wait...
Sorry, the comment you entered is too long. Please shorten it.
You didn't enter anything. Please try again.
Sorry, we can't add your comment right now. Please try again later.
To add a comment, you need permission from your parent. Ask for permission
Your parent has turned off comments.
Sorry, we can't delete your comment right now. Please try again later.
You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
Complete the security check below to finish leaving your comment.
The characters you type in the security check must match the characters in the picture or audio.

To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


Don't have a Windows Live ID? Sign up

Trackbacks

The trackback URL for this entry is:
http://gapollohan.spaces.live.com/blog/cns!1632FB29256E75B5!117.trak
Weblogs that reference this entry
  • None