visual-studio - 在 VS2010 上构建/使用 CppUnit 库

标签 visual-studio visual-studio-2010 cppunit

我下载编译了CppUnit用 Visual Studio 2010 编译。

转换后,我可以加载 CppUnitLibraries,它会给我 cppunit.lib 和 cppunit_dll.lib/dll。将 header 和库复制到一个目录后,我运行这个命令得到了很多错误。

我发现库的冲突如下

LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library

但是,下面的命令好像不起作用。

cl main.cpp complex.cpp testset.cpp /I"C:\CppUnit\include" /link /libpath:"C:\CppUnit\lib" cppunit.lib /NODEFAULTLIB:library

他们怎么了?

这是我用于编译/链接的命令。

cl main.cpp complex.cpp testset.cpp /I"C:\CppUnit\include" /link /libpath:"C:\CppUnit\lib" cppunit.lib

这是来自 VS2010 的错误消息。

cppunit.lib(TestResult.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': 

...

node@@@Z) already defined in LIBCMT.lib(typinfo.obj)
LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:lib
rary
main.exe : fatal error LNK1169: one or more multiply defined symbols found

ADDED

The CppUnit provides older version of project file (dsw), so I needed to convert the file to 2010 solution project manually.

For the error, missing /MD for compilation was the source of the problem. For other compilation warning, I needed to add /EHsc parameter.

cl /EHsc /MD /c /I"./CppUnit/include" main.cpp testset.cpp complex.cpp
link /libpath:"CppUnit/lib" main.obj testset.obj complex.obj cppunit.lib /out:cpptest_static.exe
link /libpath:"CppUnit/lib" main.obj testset.obj complex.obj cppunit_dll.lib /out:cpptest_dynamic.exe

最佳答案

您似乎是在 Debug模式下编译 CppUnit,而您现在是在 Release模式下编译当前文件。这些不应该混在一起,这就是编译器告诉你的。

解决此问题的最快方法可能是使用 VS 项目,并根据用于编译 CppUnit 的项目检查其设置。

关于您的编辑:您还在混合运行时库(例如,检查两者是否使用/MD 开关编译,也就是多线程 DLL)

关于visual-studio - 在 VS2010 上构建/使用 CppUnit 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4658754/

相关文章:

c# - Xml 文件未复制到测试输出目录

c++ - 使用现有项目进行 CppUnit 测试

visual-studio - 我可以将用于 Visual Studio 的交互式 Python 工具与现有的 ipython 内核连接起来吗

visual-studio-2010 - 如何执行与从Powershell中发布Visual Studio中的发布完全相同的功能

visual-studio - 是否有如下图所示移动光标的快捷方式?

c++ - GoogleTest 与 CppUnit : The facts

c++ - 为什么 Google Mocks 发现这个函数调用不明确?

.net - 如何在Visual Studio 2013中删除未使用的功能

c# - 将项目添加到 AddIn 中的 visual studio 文件夹右键单击菜单

c++ - C++中的模块编程