描述:
新年哈,我用ATL Wizard生成一个project,增加一个ATL Object,再加入一个函数,函数中用到了ConvertBSTRToString:
#include <comutil.h>
#pragma comment(lib, "comsupp.lib")
STDMETHODIMP CMyClass::MyFunction(BSTR sData, long *len)
{
LPSTR lpszData = _com_util::ConvertBSTRToString(sData);
....
}
Debug编译没问题,但是无论Release MiniSize还是Release MiniDependence编译都会报告讨厌的LNK2001错误:
Linking...
Creating library ReleaseMinDependency/MyTest.lib and object ReleaseMinDependency/MyTest.exp
LIBCMT.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
ReleaseMinDependency/MyTest.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
我把LPSTR lpszData = _com_util::ConvertBSTRToString(sData);注释掉就没问题。 我试过用Wizard生成一个最小的test程序都会这样,Debug没问题。
解决方案1:
去掉 _ATL_MIN_CRT
When the ATL COM AppWizard generates the default project, it defines the macro _ATL_MIN_CRT. This macro is defined so that you don't bring the C Run-Time Library into your code if you don't need it. The polygon control needs the C Run-Time Library start-up code to initialize the floating-point functions. Therefore, you need to remove the _ATL_MIN_CRT macro if you want to build a Release version. To remove the macro, click Settings on the Project menu. In the Settings For: drop-down list, choose Multiple Configurations. In the Select project configuration(s) to modify dialog box that appears, click the check boxes for all four Release versions, then click OK. On the C/C++ tab, choose the General category, then remove _ATL_MIN_CRT from the Preprocessor definitions edit box.