【问题标题】:Linking error LNK2001 when using Boost in Visual Studio 2010在 Visual Studio 2010 中使用 Boost 时出现链接错误 LNK2001
【发布时间】:2015-01-09 14:26:24
【问题描述】:

我在 Visual Studio 2010 中使用 Boost 1.54 和 Qt 5.3.2。我正在尝试使用 Boost Filesystem 的静态库。但是,每当我尝试构建我的应用程序时,都会收到以下链接错误:

libboost_filesystem-mt.lib(path.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::codecvt<wchar_t,char,int>::codecvt<wchar_t,char,int>(unsigned int)" (__imp_??0?$codecvt@_WDH@std@@QAE@I@Z)
libboost_filesystem-mt.lib(path.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) private: __thiscall std::locale::_Locimp::_Locimp(class std::locale::_Locimp const &)" (__imp_??0_Locimp@locale@std@@AAE@ABV012@@Z)
libboost_filesystem-mt.lib(path_traits.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __thiscall std::codecvt<wchar_t,char,int>::in(int &,char const *,char const *,char const * &,wchar_t *,wchar_t *,wchar_t * &)const " (__imp_?in@?$codecvt@_WDH@std@@QBEHAAHPBD1AAPBDPA_W3AAPA_W@Z)
libboost_filesystem-mt.lib(path_traits.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __thiscall std::codecvt<wchar_t,char,int>::out(int &,wchar_t const *,wchar_t const *,wchar_t const * &,char *,char *,char * &)const " (__imp_?out@?$codecvt@_WDH@std@@QBEHAAHPB_W1AAPB_WPAD3AAPAD@Z)

以下是有关我的项目设置的一些附加信息,可能会有所帮助:

  • BOOST_ALL_NO_LIB 在 配置属性 > C/C++ > 预处理器 > 预处理器定义
  • Multi-threaded (/MT) 在 配置属性 > C/C++ > 代码生成 > 运行时库
  • libboost_filesystem-mt.lib 和 libboost_system-mt.lib 在 Configuration Properties > Linker > Input > Additional Dependencies
  • ..\Libraries\1.54.0\lib_win32(Boost 库文件夹)在 Configuration Properties > Linker > General > Additional Library Directories
  • msvcrt.lib 和 msvcprt.lib 在 配置属性 > 链接器 > 输入 > 忽略特定默认库

可能是什么问题?我在 Internet 上读到 Boost 不能很好地与 Qt 配合使用。会不会是这个问题?

【问题讨论】:

  • msvcrt.lib and msvcprt.lib in Configuration Properties &gt; Linker &gt; Input &gt; Ignore Specific Default Libraries 很多时候这是问题的征兆。确保 Qt 和 boost 都是使用 Visual Studio 2010 构建的,并且您使用了相同的 CRT。
  • 有没有办法查看 Qt 和 Boost 构建后是否具有相同的 CRT?
  • 使用依赖遍历器。如果它们依赖于msvcrt.dll,则为静态 crt,否则为动态 crt。对于 vs2010,它被命名为 msvcr100.dll。
  • 我必须在 Dependency Walker 中打开什么?因为 *.lib 文件无法打开。

标签: visual-studio-2010 qt boost linker


【解决方案1】:

正如drescherjm 指出的那样,您有不同的运行时库:

  • 除非你自己构建它 Qt 使用动态版本的CRT
  • libboost_filesystem-mt.lib 是链接到 CRT 的静态版本的静态构建
  • /MT 选项指定此项目在构建时应使用CRT 的静态版本

备选方案 1:对所有人使用 CRT 的多线程动态链接版本

  • 从忽略特定默认库中删除 msvcrt.lib 和 msvcprt.lib 库
  • 使用boost_filesystem-vc100-mt-1_54.dll 和boost_system-vc100-mt-1_54.lib
  • 使用/MD 而不是/MT

备选方案 2:使用 /MT 而不是 /MD 自己构建 Qt

注意:

【讨论】:

  • 但是我必须用我的可执行文件分发 *.dll 文件,对吗?因为这是我想要阻止的事情。我只想分发一个文件。
  • 你是如何构建 Qt 的?
  • 我没有自己构建 Qt。所以我猜它使用了错误的 CRT。但它和boost有什么关系呢?为什么我会收到 boost 库的链接错误?
  • 您收到 linking 错误到 std::codecvt 等。它们是 CRT 的一部分。
  • 您使用 Ignore Specific Default Libraries 打破了提升,但如果您不使用它,您将有 2 个冲突的 crts。
猜你喜欢
  • 2013-01-17
  • 2017-08-11
  • 1970-01-01
  • 2011-04-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多