Как исправить ошибку Visual Studio 2012 LNK2019: неразрешенный внешний символ "__declspec (dllimport) public: class std:: basic_string?

Как исправить ошибку Visual Studio 2012 LNK2019: неразрешенный внешний символ "__declspec (dllimport) public: class std:: basic_string?

Я составлял решение, содержащее один exe и несколько статических проектов lib на котором exe отлично зависит от Visual Studio 2008. Статические библиотеки включают:

  • TCL: tcl84tsx.lib
  • wxWidgets: wxbase.lib
  • zlib.lib
  • ws2_32.lib
  • Xerces-c_2.lib
  • Исследование SNMP EMANATE: subagent.lib, agent.lib, emanate.lib, pack.lib, mibtable.lib, devkit.lib
  • и др.

Я загрузил решение в Visual Studio 2012 и скомпилировал все проекты в решении, но когда я пытаюсь связать exe, я получаю ошибки о неразрешенных символах для файлов в стандартной библиотеке С++, например, ниже.

Я нашел много людей с неразрешенными символами, такими как этот, но ни одна из исправлений не работает для меня. Исправления, которые я пробовал до сих пор, включают

  • Обновление проекта EXE вручную путем добавления ссылок на статические проекты lib, от которых зависит проект exe.
  • Переключение функции компоновщика "treat wchar_t as built-in type"

Выход из компоновщика Visual Studio 2012...

 1>ace_funcs.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:LBR' specification
 1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
 1>ComponentX-Win32.lib(MyOrgConsoleSktServer.obj) : warning LNK4049: locally defined symbol [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z (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> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)) imported
 1>ComponentY-Win32.lib(ORBSingleton.obj) : warning LNK4049: locally defined symbol [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z (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> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)) imported
 1>ComponentY-Win32.lib(OrbException.obj) : warning LNK4049: locally defined symbol [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z (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> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)) imported
 1>ComponentZ-Win32.lib(ExceptionHelper.obj) : warning LNK4049: locally defined symbol [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z (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> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)) imported
 1>ComponentZ-Win32.lib(ComponentCCheckpointImpl.obj) : warning LNK4217: locally defined symbol [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z (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> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)) imported in function "public: __thiscall std::logic_error::logic_error(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" ([email protected]@@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@Z)
 1>ComponentX-Win32.lib(MyOrgConsole.obj) : warning LNK4049: locally defined symbol [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z (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> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)) imported
 1>ComponentX-Win32.lib(MyOrgThreadFactory.obj) : warning LNK4049: locally defined symbol [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z (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> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)) imported
 1>ComponentZ-Win32.lib(PersistenceServiceProxy.obj) : warning LNK4049: locally defined symbol [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z (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> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)) imported
 1>ComponentZ-Win32.lib(ComponentBServiceImpl.obj) : warning LNK4049: locally defined symbol [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z (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> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)) imported
 1>ComponentZ-Win32.lib(XmlPreferencesHelper.obj) : warning LNK4217: locally defined symbol [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z (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> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)) imported in function "private: void __thiscall _CORBA_Sequence_String::copybuffer(unsigned long)" ([email protected][email protected]@[email protected])
 1>ComponentZ-Win32.lib(XmlHelper.obj) : warning LNK4049: locally defined symbol [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z (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> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)) imported
 1>ComponentA-Win32.lib(ServiceBootstrap.obj) : warning LNK4217: locally defined symbol [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z (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> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)) imported in function "public: __thiscall std::logic_error::logic_error(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" ([email protected]@@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@Z)
 1>ComponentA-Win32.lib(propertyutil.obj) : warning LNK4049: locally defined symbol [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z (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> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)) imported
 1>ComponentA-Win32.lib(SystemEnvironment.obj) : warning LNK4049: locally defined symbol [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z (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> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)) imported
 1>ComponentZ-Win32.lib(PersistenceClient.obj) : warning LNK4049: locally defined symbol [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@Z (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> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)) imported
 1>ComponentY-Win32.lib(OrbException.obj) : warning LNK4049: locally defined symbol [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected] (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)) imported
 1>ComponentX-Win32.lib(MyOrgConsole.obj) : warning LNK4049: locally defined symbol [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected] (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)) imported
 1>ComponentX-Win32.lib(MyOrgThreadFactory.obj) : warning LNK4049: locally defined symbol [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected] (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)) imported
 1>ComponentX-Win32.lib(MyOrgConsoleSktServer.obj) : warning LNK4049: locally defined symbol [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected] (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)) imported
 1>ComponentY-Win32.lib(ORBSingleton.obj) : warning LNK4217: locally defined symbol [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected] (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)) imported in function "public: virtual __thiscall OrbException::~OrbException(void)" ([email protected]@[email protected])
 1>ComponentZ-Win32.lib(XmlPreferencesHelper.obj) : warning LNK4049: locally defined symbol [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected] (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)) imported
 -- snip --
 1>ComponentA-Win32.lib(ServiceBootstrap.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) 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> >::substr(unsigned int,unsigned int)const " ([email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@Z) referenced in function "private: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall ServiceBootstrap::trimmed(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,char const *)" ([email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@Z)
 1>ComponentA-Win32.lib(ServiceBootstrap.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: unsigned int __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::find_last_not_of(char const *,unsigned int,unsigned int)const " ([email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]) referenced in function "private: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall ServiceBootstrap::trimmed(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,char const *)" ([email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@Z)
 1>ComponentA-Win32.lib(ServiceBootstrap.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: unsigned int __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::find_first_not_of(char const *,unsigned int,unsigned int)const " ([email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]) referenced in function "private: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall ServiceBootstrap::trimmed(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,char const *)" ([email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@Z)
 1>ComponentA-Win32.lib(ServiceBootstrap.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl std::operator+<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,char const *)" ([email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]) referenced in function "private: void __thiscall ServiceBootstrap::verifyBootstrapProperties(void)" ([email protected]@@AAEXXZ)
 1>ComponentZ-Win32.lib(PersistenceServiceProxy.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl std::operator+<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,char const *)" ([email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected])
 1>ComponentA-Win32.lib(ServiceBootstrap.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl std::operator+<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" ([email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]) referenced in function "public: class std::map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > > __thiscall ServiceBootstrap::getBootstrapProperties(void)" ([email protected]@@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected][email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@[email protected][email protected][email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@[email protected]@[email protected]@XZ)
 1>ComponentZ-Win32.lib(PersistenceServiceProxy.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl std::operator+<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" ([email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected])
 1>ComponentA-Win32.lib(propertyutil.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::_Mutex::_Lock(void)" ([email protected][email protected]@@QAEXXZ) referenced in function "public: __thiscall std::basic_ostream<char,struct std::char_traits<char> >::_Sentry_base::_Sentry_base(class std::basic_ostream<char,struct std::char_traits<char> > &)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected]@@Z)
 1>ComponentZ-Win32.lib(XmlHelper.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::_Mutex::_Lock(void)" ([email protected][email protected]@@QAEXXZ)
 -- snip --
 1>.\Debug/sComponentC.exe : fatal error LNK1120: 22 unresolved externals
 ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Ответ 1

В свойствах → c/С++ → Laguage, я установил wchar_t как встроенный тип в No, и он решил мою проблему.

Ответ 2

Если вы уже пробовали следующие параметры:

  • Обновление проекта EXE вручную путем добавления ссылок на статические проекты lib, от которых зависит проект exe.
  • Переключение опции "treat wchar_t as built-in type"

Попробуйте настроить проект на x64, выполнив следующие шаги:

  • Щелкните правой кнопкой мыши по Solution 'ProjectName'
  • Выберите Configuration Manager...
  • Измените platform проекта, который вы пытаетесь связать .lib файл с x64 с Win32 (или наоборот)
  • Восстановить решение

Это фактически решило мою проблему. Я не знал, скомпилирована ли моя внешняя библиотека для 32-разрядной или 64-разрядной версии.

Ответ 3

Даже я столкнулся с подобными ошибками в визуальной студии. Причиной такого рода ошибок является

1) Возможно, вы включили несколько библиотек, которые конфликтуют друг с другом.  Иногда один класс в библиотеке может конфликтовать с другим классом в другой библиотеке.

2) Возможно, вы включили библиотеки из каталогов. Проверьте путь библиотек еще раз.

3) В свойствах проекта вам нужно указать библиотеки и файлы заголовков (если нужно включить). Еще раз проверьте правильность путей.