在ATL . server工程中加入一个本身开发的dll库,结果致使上述问题。dll的入口函数问题。app
解决办法就是,去掉编译器选项的_ATL_MIN_CRT宏定义。ide
转:函数
有的时候, 在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 从工程设置中去掉便可ui
msdn文档:this
Two advantages of ATL are that it allows you to:spa
Minimize your image sizecode
Minimize your reliance on run-time DLLsorm
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.server
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.blog
![]() |
---|
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: