重建C ++时的链接器错误 - CLI项目std :: basic_string

时间:2011-06-11 15:45:53

标签: .net winforms visual-c++ visual-studio-2008 c++-cli

我正在Visual Studio 2008中编写一个C ++应用程序。我已经在我的项目中添加了一个Windows窗体,启用了CLR支持并添加了一行来实例化该窗体。

由于这样做,我得到了一堆链接器错误,如下所示:

  

错误LNK2001:未解析的外部符号“public:virtual class std :: basic_string< char,struct std :: char_traits< char&gt ;, class std :: allocator< char>> __thiscall ...”(...)

任何想法我做错了什么?

完整错误(匿名):

1>Linking...
1>   Creating library C:\***.lib and object C:\***.exp
1>getProducts.obj : error LNK2001: unresolved external symbol "public: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall ***::GetClassName(void)const " (?GetClassName@***@@UBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
1>getProducts.obj : error LNK2001: unresolved external symbol "protected: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall ***::GetClassName(void)const " (?GetClassName@***@@MBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
1>getProducts.obj : error LNK2001: unresolved external symbol "protected: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall ***::GetClassName(void)const " (?GetClassName@***@@MBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
1>getProducts.obj : error LNK2001: unresolved external symbol "protected: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall ***::GetClassName(void)const " (?GetClassName@***@@MBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
1>getProducts.obj : error LNK2001: unresolved external symbol "protected: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall ***::GetClassName(void)const " (?GetClassName@***@@MBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
1>getProducts.obj : error LNK2001: unresolved external symbol "protected: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall ***::GetClassName(void)const " (?GetClassName@***@@MBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
1>getProducts.obj : error LNK2001: unresolved external symbol "protected: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall ***::GetClassName(void)const " (?GetClassName@***@@MBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
1>getProducts.obj : error LNK2001: unresolved external symbol "protected: virtual class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall ***::GetClassName(void)const " (?GetClassName@***@@MBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
1>MSVCRT.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\***.exe : fatal error LNK1120: 9 unresolved externals
1>Build log was saved at "file://c:\***\BuildLog.htm"
1>getProducts - 10 error(s), 12 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ========

1 个答案:

答案 0 :(得分:1)

如果在项目中使用多个用户创建的文件,则可能会发生错误,因为您未将变量声明为extern或多次包含头文件。请参阅以下网站以获取问题的答案:

www.gamedev.net/page/resources/_/technical/general-programming/organizing-code-files-in-c-and-c-r1798