谁用过cppunit?请指点一下迷津

yanwuhuan 2003-10-17 03:39:09
使用cppunit1.8.0,编译器使用VC++6.0,OS是win2k sp4,
结果编译成功,但是链接失败。
提示:symbol已经在库文件msvcrt.lib定义,请用/nodefaultlibrary:library什么的东东来避免,但摸了半天还是搞不定。

请用过的xdjm们指点一二。
...全文
135 点赞 收藏 15
写回复
15 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
flyelf 2003-10-24
我怎么没有遇到这个问题啊
回复
yanwuhuan 2003-10-24
我去试试最新的吧。
多谢诸位的热心帮助。
回复
yisan 2003-10-24
我用的是1.9.11,在VS2003(VC7.1)下没有问题。
建议你去下最新版本。
回复
daizh 2003-10-24
Linker Tools Error LNK2005
symbol already defined in object

The given symbol, displayed in its decorated form, was multiply defined.

Tips

One of the following may be a cause:

The most common cause of this error is accidentally linking with both the single-threaded and multithreaded libraries. Ensure that the application project file includes only the appropriate libraries and that any third-party libraries have appropriately created single-threaded or multithreaded versions.


The given symbol was a packaged function (created by compiling with /Gy) and was included in more than one file but was changed between compilations. Recompile all files that include the symbol.


The given symbol was defined differently in two member objects in different libraries, and both member objects were used.


An absolute was defined twice, with a different value in each definition.
回复
yanwuhuan 2003-10-21
多谢多谢,我现在一筹莫展,都想放弃它了:(

Deleting intermediate files and output files for project 'tt - Win32 Release'.
--------------------Configuration: tt - Win32 Release--------------------
Compiling...
main.cpp
MathTest.cpp
Linking...
msvcprt.lib(MSVCP60.dll) : error LNK2005: "private: void __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::_Copy(unsigned int)" (?_Copy@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAEXI@Z)
already defined in main.obj
msvcprt.lib(MSVCP60.dll) : error LNK2005: "private: void __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::_Tidy(bool)" (?_Tidy@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAEX_N@Z) alread
y defined in main.obj
msvcprt.lib(MSVCP60.dll) : error LNK2005: "void __cdecl std::_Xlen(void)" (?_Xlen@std@@YAXXZ) already defined in libcp.lib(string.obj)
msvcprt.lib(MSVCP60.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??1?$basic_string@
DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in main.obj
msvcprt.lib(MSVCP60.dll) : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::assign(class s
td::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned int,unsigned int)" (?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@ABV12@II@Z) already defined in main.obj
msvcprt.lib(MSVCP60.dll) : error LNK2005: "private: void __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::_Eos(unsigned int)" (?_Eos@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAEXI@Z) a
lready defined in main.obj
msvcprt.lib(MSVCP60.dll) : error LNK2005: "private: bool __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::_Grow(unsigned int,bool)" (?_Grow@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAE
_NI_N@Z) already defined in main.obj
msvcprt.lib(MSVCP60.dll) : error LNK2005: "private: void __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::_Split(void)" (?_Split@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAEXXZ) alread
y defined in main.obj
msvcprt.lib(MSVCP60.dll) : error LNK2005: "void __cdecl std::_Xran(void)" (?_Xran@std@@YAXXZ) already defined in libcp.lib(string.obj)
msvcprt.lib(MSVCP60.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(char const *,class basic_st
ring<char,struct std::char_traits<char>,class std::allocator<char> >::allocator<char> const &)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBDABV?$allocator@D@1@@Z) already defined in main.obj
msvcprt.lib(MSVCP60.dll) : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::erase(unsigned
int,unsigned int)" (?erase@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@II@Z) already defined in libcp.lib(string.obj)
LINK : warning LNK4049: locally defined symbol "_memmove" imported
LINK : warning LNK4049: locally defined symbol ""public: virtual __thiscall exception::~exception(void)" (??1exception@@UAE@XZ)" imported
LINK : warning LNK4049: locally defined symbol ""public: __thiscall exception::exception(class exception const &)" (??0exception@@QAE@ABV0@@Z)" imported
LINK : warning LNK4049: locally defined symbol ""public: __thiscall exception::exception(void)" (??0exception@@QAE@XZ)" imported
cppunit.lib(TestCase.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: char const * __thiscall type_info::name(void)const " (__imp_?name@type_info@@QBEPBDXZ)
Release/tt.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

tt.exe - 13 error(s), 4 warning(s)

根据这个提示,我又加了一个nodefault:msvcprt.lib,但是更不行,这个就不贴了。
回复
yanwuhuan 2003-10-21
多谢多谢,我现在一筹莫展,都想放弃它了:(

Deleting intermediate files and output files for project 'tt - Win32 Release'.
--------------------Configuration: tt - Win32 Release--------------------
Compiling...
main.cpp
MathTest.cpp
Linking...
msvcprt.lib(MSVCP60.dll) : error LNK2005: "private: void __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::_Copy(unsigned int)" (?_Copy@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAEXI@Z)
already defined in main.obj
msvcprt.lib(MSVCP60.dll) : error LNK2005: "private: void __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::_Tidy(bool)" (?_Tidy@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAEX_N@Z) alread
y defined in main.obj
msvcprt.lib(MSVCP60.dll) : error LNK2005: "void __cdecl std::_Xlen(void)" (?_Xlen@std@@YAXXZ) already defined in libcp.lib(string.obj)
msvcprt.lib(MSVCP60.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??1?$basic_string@
DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in main.obj
msvcprt.lib(MSVCP60.dll) : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::assign(class s
td::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned int,unsigned int)" (?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@ABV12@II@Z) already defined in main.obj
msvcprt.lib(MSVCP60.dll) : error LNK2005: "private: void __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::_Eos(unsigned int)" (?_Eos@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAEXI@Z) a
lready defined in main.obj
msvcprt.lib(MSVCP60.dll) : error LNK2005: "private: bool __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::_Grow(unsigned int,bool)" (?_Grow@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAE
_NI_N@Z) already defined in main.obj
msvcprt.lib(MSVCP60.dll) : error LNK2005: "private: void __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::_Split(void)" (?_Split@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAEXXZ) alread
y defined in main.obj
msvcprt.lib(MSVCP60.dll) : error LNK2005: "void __cdecl std::_Xran(void)" (?_Xran@std@@YAXXZ) already defined in libcp.lib(string.obj)
msvcprt.lib(MSVCP60.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(char const *,class basic_st
ring<char,struct std::char_traits<char>,class std::allocator<char> >::allocator<char> const &)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBDABV?$allocator@D@1@@Z) already defined in main.obj
msvcprt.lib(MSVCP60.dll) : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::erase(unsigned
int,unsigned int)" (?erase@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@II@Z) already defined in libcp.lib(string.obj)
LINK : warning LNK4049: locally defined symbol "_memmove" imported
LINK : warning LNK4049: locally defined symbol ""public: virtual __thiscall exception::~exception(void)" (??1exception@@UAE@XZ)" imported
LINK : warning LNK4049: locally defined symbol ""public: __thiscall exception::exception(class exception const &)" (??0exception@@QAE@ABV0@@Z)" imported
LINK : warning LNK4049: locally defined symbol ""public: __thiscall exception::exception(void)" (??0exception@@QAE@XZ)" imported
cppunit.lib(TestCase.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: char const * __thiscall type_info::name(void)const " (__imp_?name@type_info@@QBEPBDXZ)
Release/tt.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

tt.exe - 13 error(s), 4 warning(s)

根据这个提示,我又加了一个nodefault:msvcprt.lib,但是更不行,这个就不贴了。
回复
daizh 2003-10-20
现在的错误信息是什么,贴一下。
回复
yanwuhuan 2003-10-20
我用的是IBM developerworks上面的一个示例程序,很小,贴在后面。有三个文件main.cpp、mathtest.cpp、mathtest.h。
操作步骤如下:
打开vc++6.0,新建一个空的Win32 Console Application,加入两个.cpp文件,
和cppunit.lib,再如daizh()兄所言,加入了nodefaultlibrary,但还是不行,
是不是中间有某一个步骤错了?

// main.cpp
#include "MathTest.h"
#include "cppunit/ui/text/TestRunner.h"
#include "cppunit/TestCaller.h"
#include "cppunit/TestSuite.h"

int main()
{
CppUnit::TextUi::TestRunner runner;
CppUnit::TestSuite *suite= new CppUnit::TestSuite();

// 添加一个测试用例
suite->addTest(new CppUnit::TestCaller<MathTest> (
"testAdd", MathTest::testAdd));

// 指定运行TestSuite
runner.addTest( suite );
// 开始运行, 自动显示测试进度和测试结果
runner.run( "", true ); // Run all tests and wait
return 0;
}

// MathTest.cpp
#include "MathTest.h"
#include "cppunit/TestAssert.h"

void MathTest::setUp()
{
m_value1 = 2;
m_value2 = 3;
}

void MathTest::tearDown()
{

}

void MathTest::testAdd()
{
int result = m_value1 + m_value2;
CPPUNIT_ASSERT( result == 5 );
}

// MathTest.h
#include "cppunit/TestFixture.h"


class MathTest : public CppUnit::TestFixture {
protected:
int m_value1, m_value2;

public:
MathTest() {}

// 初始化函数
void setUp ();
// 清理函数
void tearDown();

// 测试加法的测试函数
void testAdd ();
// 可以添加新的测试函数
};
回复
oyd 2003-10-18
cppunit是用来做单元测试的那个东西吗?
听别人说不好用啊
回复
Darkay_Lee 2003-10-18
补充,VC7的话直接在link的页面就有个空让你自己填写忽略那个确实库
回复
Darkay_Lee 2003-10-18
就是缺省库和cppunit冲突了,要屏蔽那个库,方法 daizh() 已经说了。
回复
dddd8888 2003-10-18
没用过
回复
daizh 2003-10-17
你按照我说的步骤做呀
回复
Andy84920 2003-10-17
还不知道是个什么东西!
回复
daizh 2003-10-17
在vc中project->settings->link->Project otions:最后添加/nodefaultlib:"msvcrt.lib"
回复
发帖
工具平台和程序库
创建于2007-09-28

2.4w+

社区成员

C/C++ 工具平台和程序库
申请成为版主
帖子事件
创建了帖子
2003-10-17 03:39
社区公告
暂无公告