VC编译错误:LIBCMT.lib(crt0.obj) : error LNK2001: un...

错误信息:LIBCMT.lib(crt0.obj) : error LNK2001: unresolved external symbol _main

 在ATL . server工程中加入一个自己开发的dll库,结果导致上述问题。dll的入口函数问题。

解决办法就是,去掉编译器选项的_ATL_MIN_CRT宏定义

有的时候, 在ATL控件中可能需要使用C/C++运行库, 这个时候由于默认的ATL工程中定义了宏_ATL_MIN_CRT,那么,可能阻止了release工程的编译, 出现类似于下面的错误

MSVCRT.lib(MSVCRT.dll) : error LNK2005: _free already defined in StdAfx.obj
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _malloc already defined in StdAfx.obj
MSVCRT.lib(MSVCRT.dll) : error LNK2005: _realloc already defined in StdAfx.obj
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: _free already defined in StdAfx.obj; second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: _malloc already defined in StdAfx.obj; second definition ignored
MSVCRT.lib(MSVCRT.dll) : warning LNK4006: _realloc already defined in StdAfx.obj; second definition ignored


因此, 只需要把 _ATL_MIN_CRT 从工程设置中去掉即可

 

msdn文档

Two advantages of ATL are that it allows you to:

  • Minimize your image size

  • Minimize your reliance on run-time DLLs

However, you might want to take advantage of some functions provided by the CRT. Because statically linking increases your image size, and dynamically linking ties you to the run-time DLL, using the CRT may deprive you of these key goals for using ATL.

To help solve this dilemma, ATL provides a solution: the _ATL_MIN_CRT macro. The _ATL_MIN_CRT macro, activated by setting the General Property option Minimize CRT Use in ATL to Yes, provides alternative implementations for many of the common CRT functions that would otherwise require the CRT startup code.

NoteNote

Console applications do not support _ATL_MIN_CRT. If you use _ATL_MIN_CRT in an ATL console application, you will receive link error "LNK2005: __osplatform already defined in atlmincrt.lib(atlinit.obj)."

Remember that using the _ATL_MIN_CRT macro does not guarantee that no functions from the CRT will be required.

If you use a function that requires the CRT startup code to operate properly, you will get the following linker error:

LIBCMT.LIB(crt0.obj) : error LNK2001: unresolved external symbol _main

Providing your own implementation of _main does not solve this problem: you must either remove reliance on the functions that require the CRT startup code, or you must either statically link the startup code in your image or dynamically link to the CRT.

When _ATL_MIN_CRT is used without the /GS- compiler option, ATL headers will require the static CRT library. For more information, see /GS (Buffer Security Check).

For more information on linking to the CRT, see Linking to the CRT in Your ATL Project.

To identify the CRT startup code, see the following topics:

转载于:https://my.oschina.net/u/136923/blog/70180

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值