我下载编译了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/