我有一个MFC项目,在Visual Studio 2012下使用C++ Rest SDK (Casablanca
)实现了http客户端连接,可以很好地编译。
然后我添加了一个Microsoft单元测试项目,但是我无法成功构建单元测试项目。
在我的主项目中,环境设置为“在静态库中使用MFC”、“无公共(public)语言运行时支持”和“多线程调试(/MTd)。” 我的测试项目的环境与主项目相同。错误信息显示:
“error LNK2005: "void * __cdecl operator new[](unsigned int)" (??_U@YAPAXI@Z) already defined in libcpmtd.lib(newaop.obj).”
此外,我还尝试将测试项目的环境更改为“Common Language Runtime Support (/clr)”和“Multi-threaded Debug DLL (/MDd)”。原来的错误消失了但是新的错误来了:
“error C1189: #error : is not supported when compiling with /clr or /clr:pure. c:\program files (x86)\microsoft visual studio 11.0\vc\include\atomic line 9”
我不知道如何克服这些问题。谁能给我一些建议或解决方案?谢谢。
最佳答案
CRT 库对新增、删除功能使用弱外部链接。 MFC 库还包含新建、删除函数。这些函数要求在链接 CRT 库之前链接 MFC 库。请查看http://support.microsoft.com/kb/148652
基于VS2005的解决方案:
go to project>properties>configuration properties>linker>input
add to "Additional dependency" -> Nafxcwd.lib Libcmtd.lib
add to "ignore specific library" -> Nafxcwd.lib;Libcmtd.lib
关于c++ - 无法同时使用C++ Rest SDK和微软单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24362415/