gpt4 book ai didi

c++ - 在 VS.NET 2010 中构建 C++ 单元测试项目时出现链接错误

转载 作者:太空狗 更新时间:2023-10-29 21:49:53 25 4
gpt4 key购买 nike

我正在尝试构建一个非常简单的 C++ 单元测试项目。设置恰好与此完全相同 blog描述。我构建了一个静态库 TestLib.lib 和一个名为 TestProject 的 C++ 单元测试项目。这两个项目都使用平台工具集 v100。

TeSTLib 只包含一个类。

BaseClass.h

#pragma once 

class BaseClass
{
public:
void Method1();
};

BaseClass.cpp

#include "BaseClass.h"
#include <iostream>
#include <list>

using namespace std;

void BaseClass::Method1()
{
list<int> dummy(0);
cout << "Hello world";
}

TestProject 只有一个测试用例。

#include "BaseClass.h"
#include <list>
.
.
.
[TestMethod]
void TestMethod1()
{
BaseClass b;
b.Method1();
};

看起来如果我有一个 #include <list>#include "BaseClass.h" 之后(在 test.cpp 中)我会出现以下链接错误。如果我取出 #include <list> ,我根本没有链接错误。

TestLib.lib(BaseClass.obj) : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification
MSVCMRT.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std.basic_string<char,std::char_traits<char>,std::allocator<char> >): (0x0200003d).
MSVCMRT.lib(locale0_implib.obj) : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std.basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >): (0x02000063).
LINK : fatal error LNK1255: link failed because of metadata errors

如果我在测试程序中再添加一行,链接错误就会消失,如下所示:

#include "BaseClass.h"
#include <list>
.
.
.
[TestMethod]
void TestMethod1()
{
std::list<int> dummy(0);
BaseClass b;
b.Method1();
};

但是,现在,我有两个链接警告。我不确定它们是否与之前的链接错误有关。

TestLib.lib(BaseClass.obj) : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/INCREMENTAL:NO' specification
LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library

谁能解释一下为什么?我在这里错过了一些明显的东西吗?

最佳答案

错误是否仅在编译调试配置时出现?如果是这样,它可能与您的 C++ 运行时库链接有关:

http://social.msdn.microsoft.com/Forums/eu/vclanguage/thread/e5a78770-4d99-40b7-951f-e4466d2744a8

关于c++ - 在 VS.NET 2010 中构建 C++ 单元测试项目时出现链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7549878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com