在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: