c++ - vector LNK2005 错误

标签 c++ visual-studio-2008 lnk

本博客Cubic建议尝试四件事,然后或多或少地寻求帮助

  • 重建、检查
  • 勾选Runtime Libraries,只有一个项目
  • 检查入口点,检查 SUBSYSTEM:CONSULE
  • 检查强制包含的 .lib 文件,我没有看到 #pragma comment(lib, ...)
  • 有关在链接器选项中打开/VERBOSE 的一些信息,我没有看到该选项

我会发布一些代码,但这是一个 LNK 错误;它没有提供太多信息。

  • LNK2005:“类 std::vector,类 std::allocator >,类 std::allocator,类 std::allocator >> >,类 std::allocator,类 std::allocator >,类 std: :allocator,class std::allocator >> >> > list1"(?list1@@3V?$vector@V?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@ D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@V? $allocator@V?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits @D@std@@V?$allocator@D@2@@std@@@2@@std@@@2@@std@@A) 已在 msproject.obj 中定义
  • LNK2005:“类 std::vector,类 std::allocator >,类 std::allocator,类 std::allocator >> >,类 std::allocator,类 std::allocator >,类 std: :allocator,class std::allocator >> >> > list1"(?list1@@3V?$vector@V?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@ D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@V? $allocator@V?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits @D@std@@V?$allocator@D@2@@std@@@2@@std@@@2@@std@@A) 已在 msproject.obj 中定义

我看到它与 msproject 中已经定义的 vector 有关 - 我确保 vector 具有不同的名称。这是 header # include <vector> 的东西吗? ;我尝试注释掉一些#includes 以进行检查,但还是一样。

最佳答案

您似乎不止一次定义了 list1。 (顺便说一句,顾名思义它应该是一个 std::list,但这超出了问题的范围)

你有吗

std::vector<std::string> list1;

在头文件中?该 header 是否包含在多个翻译单元中?

如果你想要一个全局的,你需要在header中使用extern:

extern std::vector<std::string> list1;

并将定义移动到单个实现文件中。

关于c++ - vector LNK2005 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11658514/

相关文章:

c++ - 来自抽象类的新派生类

.net - VS 2008 中的表单设计器有问题吗?

.net - Visual Studio 2008 中的用户设置与应用程序设置与资源

python - 使用python3在Windows中创建文件的快捷方式(.lnk)

c++ - 在 C++ 中用负整数求模

c++ - qt 如何通过 connect(Signal,Slot) 将 qshortcut() 的 QkeySequence 传递给函数?

c++ - LNK2019错误未解析的外部符号

c++ - 为什么我的计算出错了?

c++ - 从 VC++ 6 升级到 MSVC 2005 后 MFC 断言失败

visual-studio-2008 - ReSharper 卸载 - Visual Studio 不再显示正确的错误突出显示