visual-studio - Visual C++ 中多个项目之间的链接器错误

标签 visual-studio visual-c++ projects-and-solutions

我有一个包含多个项目的解决方案。我有一个“主”项目,它充当菜单,用户可以从那里访问任何其他项目。在这个主项目中,每个调用的函数都会出现链接器错误。如何避免这些链接器错误?我已经在“项目依赖项...”对话框中设置了项目依赖项。

谢谢

编辑——我按照建议做了并将输出文件夹添加到链接器的附加目录中。但是,现在我收到了如下一百万个错误:

3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: void __thiscall std::basic_ios >::setstate(int,bool)" (?setstate@?$basic_ios@DU?$char_traits@D@std@@@std@@QAEXH_N@Z) already defined in panels.lib(panel_main.obj)
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: int __thiscall std::ios_base::width(int)" (?width@ios_base@std@@QAEHH@Z) already defined in panels.lib(panel_main.obj)
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: int __thiscall std::basic_streambuf >::sputn(char const *,int)" (?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHPBDH@Z) already defined in panels.lib(panel_main.obj)
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: static bool __cdecl std::char_traits::eq_int_type(int const &,int const &)" (?eq_int_type@?$char_traits@D@std@@SA_NABH0@Z) already defined in panels.lib(panel_main.obj)
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: static int __cdecl std::char_traits::eof(void)" (?eof@?$char_traits@D@std@@SAHXZ) already defined in panels.lib(panel_main.obj)
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: int __thiscall std::basic_streambuf >::sputc(char)" (?sputc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHD@Z) already defined in panels.lib(panel_main.obj)
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: class std::basic_streambuf > * __thiscall std::basic_ios >::rdbuf(void)const " (?rdbuf@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEPAV?$basic_streambuf@DU?$char_traits@D@std@@@2@XZ) already defined in panels.lib(panel_main.obj)
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: char __thiscall std::basic_ios >::fill(void)const " (?fill@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEDXZ) already defined in panels.lib(panel_main.obj)
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: int __thiscall std::ios_base::flags(void)const " (?flags@ios_base@std@@QBEHXZ) already defined in panels.lib(panel_main.obj)
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: int __thiscall std::ios_base::width(void)const " (?width@ios_base@std@@QBEHXZ) already defined in panels.lib(panel_main.obj)
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: static unsigned int __cdecl std::char_traits::length(char const *)" (?length@?$char_traits@D@std@@SAIPBD@Z) already defined in panels.lib(panel_main.obj)
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: class std::basic_ostream > & __thiscall std::basic_ostream >::flush(void)" (?flush@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV12@XZ) already defined in panels.lib(panel_main.obj)
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: class std::basic_ostream > * __thiscall std::basic_ios >::tie(void)const " (?tie@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEPAV?$basic_ostream@DU?$char_traits@D@std@@@2@XZ) already defined in panels.lib(panel_main.obj)
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: bool __thiscall std::ios_base::good(void)const " (?good@ios_base@std@@QBE_NXZ) already defined in panels.lib(panel_main.obj)
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: void __thiscall std::basic_ostream >::_Osfx(void)" (?_Osfx@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEXXZ) already defined in panels.lib(panel_main.obj)
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: void __thiscall std::basic_streambuf >::_Lock(void)" (?_Lock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEXXZ) already defined in panels.lib(panel_main.obj)
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: void __thiscall std::basic_streambuf >::_Unlock(void)" (?_Unlock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEXXZ) already defined in panels.lib(panel_main.obj)
3>msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: class std::locale::facet * __thiscall std::locale::facet::_Decref(void)" (?_Decref@facet@locale@std@@QAEPAV123@XZ) already defined in panels.lib(panel_main.obj)
3>libcpmtd.lib(ios.obj) : error LNK2005: "private: static void __cdecl std::ios_base::_Ios_base_dtor(class std::ios_base *)" (?_Ios_base_dtor@ios_base@std@@CAXPAV12@@Z) already defined in msvcprtd.lib(MSVCP90D.dll)
3>libcpmtd.lib(ios.obj) : error LNK2005: "public: static void __cdecl std::ios_base::_Addstd(class std::ios_base *)" (?_Addstd@ios_base@std@@SAXPAV12@@Z) already defined in msvcprtd.lib(MSVCP90D.dll)
3>libcpmtd.lib(locale0.obj) : error LNK2005: "void __cdecl _AtModuleExit(void (__cdecl*)(void))" (?_AtModuleExit@@YAXP6AXXZ@Z) already defined in msvcprtd.lib(locale0_implib.obj)
3>libcpmtd.lib(locale0.obj) : error LNK2005: __Fac_tidy already defined in msvcprtd.lib(locale0_implib.obj)
3>libcpmtd.lib(locale0.obj) : error LNK2005: "private: static void __cdecl std::locale::facet::facet_Register(class std::locale::facet *)" (?facet_Register@facet@locale@std@@CAXPAV123@@Z) already defined in msvcprtd.lib(locale0_implib.obj)
3>libcpmtd.lib(locale0.obj) : error LNK2005: "private: static class std::locale::_Locimp * __cdecl std::locale::_Getgloballocale(void)" (?_Getgloballocale@locale@std@@CAPAV_Locimp@12@XZ) already defined in msvcprtd.lib(MSVCP90D.dll)
3>libcpmtd.lib(locale0.obj) : error LNK2005: "private: static class std::locale::_Locimp * __cdecl std::locale::_Init(void)" (?_Init@locale@std@@CAPAV_Locimp@12@XZ) already defined in msvcprtd.lib(MSVCP90D.dll)
3>libcpmtd.lib(locale0.obj) : error LNK2005: "public: static void __cdecl std::_Locinfo::_Locinfo_ctor(class std::_Locinfo *,class std::basic_string,class std::allocator > const &)" (?_Locinfo_ctor@_Locinfo@std@@SAXPAV12@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z) already defined in msvcprtd.lib(MSVCP90D.dll)
3>libcpmtd.lib(locale0.obj) : error LNK2005: "public: static void __cdecl std::_Locinfo::_Locinfo_dtor(class std::_Locinfo *)" (?_Locinfo_dtor@_Locinfo@std@@SAXPAV12@@Z) already defined in msvcprtd.lib(MSVCP90D.dll)
3>libcpmtd.lib(xlock.obj) : error LNK2005: "public: __thiscall std::_Lockit::_Lockit(int)" (??0_Lockit@std@@QAE@H@Z) already defined in msvcprtd.lib(MSVCP90D.dll)
3>libcpmtd.lib(xlock.obj) : error LNK2005: "public: __thiscall std::_Lockit::~_Lockit(void)" (??1_Lockit@std@@QAE@XZ) already defined in msvcprtd.lib(MSVCP90D.dll)

最佳答案

在不知道您的解决方案的任何其他细节的情况下,很难判断,但是全部重建可能会有所帮助。当不同体系结构有混合的目标文件时,有时会发生这种情况。

您可能还想考虑使用“引用”而不是“依赖项”

编辑:

在您发布的内容之后,您与标准库的链接似乎不一致。可能是其中一个项目静态链接标准库,而其他项目动态链接? (见项目属性->链接器)或者一个到发布运行时,而其他的去调试? (虽然最后一个应该是可能的,但需要注意)

关于visual-studio - Visual C++ 中多个项目之间的链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/604484/

相关文章:

c# - 如何将 Visual Studio 默认为 C# 项目而不是 VB.NET?

c++ - 将 SFML 与 GitHub 上的 C++ 项目同步

c++ - MSVC 编译器从 if/else 语句反汇编代码

project-management - 理解未注释和复杂项目的最佳或最快方式

c# - 来自外部项目的引用接口(interface)

c# - 应用程序配置为使用 IIS (Visual Studio 2017/2019)

c++ - 智能感知 : command-line error: invalid macro definition

c# - Web.config iis url重写

c++ - 全局变量析构函数未调用,从哪里开始?

visual-studio - 使用同一Visual Studio 2005解决方案的不同版本/分支