我下载并编译了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
最佳答案
好像您是在调试模式下编译CppUnit一样,现在您正在以发布模式编译当前文件。那些不要混在一起,这就是编译器告诉您的。
解决此问题的最快方法可能是使用VS项目,并对照用于编译CppUnit的项目检查其设置。
在编辑上添加:您还在混合运行时库(例如,检查是否都使用/ MD开关(也称为多线程DLL)进行编译)
关于visual-studio - 在VS2010上构建/使用CppUnit库,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4658754/