链接器错误(LNK2001)与CLI / CLR代码中的Boost库(filesystem.hpp)

时间:2013-05-23 18:02:48

标签: boost linker lnk2001

我一直试图解决这个问题几天,似乎无法找到解决方案。我正在MSVS 2012中创建一个Windows窗体应用程序(但应用程序本身使用的是MSVS 2010二进制文件和.NET 4.0)。该应用程序需要使用CLI / CLR托管代码。

我已按照Getting Started指南使用以下内容构建了库:

bootstrap.bat
.\b2.exe --toolset=msvc-10.0 --build-type=complete

我将目录设置/链接到Visual Studio中的项目:

  • C / C ++>一般>其他包含目录> “C:\ Program Files%28x86%29 \ Microsoft Visual Studio 11.0 \ Boost”
  • 链接器>一般>其他图书馆目录> “C:\ Program Files%28x86%29 \ Microsoft Visual Studio 11.0 \ Boost \ stage \ lib”

以下是我在之前编译和执行的代码中添加的所有内容:

#define BOOST_LIB_DIAGNOSTIC                 //show diagnostics
#define BOOST_USE_WINDOWS_H                  
#define BOOST_FILESYSTEM_NO_DEPRECATED       //don't use deprecated code
#include <boost/filesystem.hpp>

using namespace boost::filesystem;

以下是构建的输出(Release / Win32):

1>------ Build started: Project: PROJECT_NAME (Visual Studio 2010), Configuration: Release Win32 ------
1>  PROJECT_NAME.cpp
1>  Linking to lib file: libboost_filesystem-vc100-mt-1_53.lib
1>  Linking to lib file: libboost_system-vc100-mt-1_53.lib
1>PROEJCT_NAME.obj : error LNK2001: unresolved external symbol "class boost::system::error_category const & __clrcall boost::system::system_category(void)" (?system_category@system@boost@@$$FYMABVerror_category@12@XZ)
1>PROJECT_NAME.obj : error LNK2001: unresolved external symbol "class boost::system::error_category const & __clrcall boost::system::generic_category(void)" (?generic_category@system@boost@@$$FYMABVerror_category@12@XZ)
1>PROJECT_NAME.obj : error LNK2001: unresolved external symbol "void __clrcall boost::filesystem::path_traits::convert(wchar_t const *,wchar_t const *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > &,class std::codecvt<wchar_t,char,int> const &)" (?convert@path_traits@filesystem@boost@@$$FYMXPB_W0AAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV?$codecvt@_WDH@5@@Z)
1>PROJECT_NAME.obj : error LNK2001: unresolved external symbol "public: static class std::codecvt<wchar_t,char,int> const & __clrcall boost::filesystem::path::codecvt(void)" (?codecvt@path@filesystem@boost@@$$FSMABV?$codecvt@_WDH@std@@XZ)
1>PROJECT_NAME.obj : error LNK2001: unresolved external symbol "class boost::system::error_code __clrcall boost::filesystem::detail::dir_itr_close(void * &)" (?dir_itr_close@detail@filesystem@boost@@$$FYM?AVerror_code@system@3@AAPAX@Z)
1>C:\Users\USERNAME\Documents\Visual Studio 2012\Projects\PROJECT_NAME\Release\PROJECT_NAME.exe : fatal error LNK1120: 5 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我还没有正确构建/链接的内容吗?如果需要更多信息,请告诉我,我将尽我所能。

1 个答案:

答案 0 :(得分:1)

我知道,复活一篇旧帖子,但我花了很长时间试图找出类似的issue,所以我发帖给下一个遇到类似问题的人。

为此,您需要使用VS2012构建Boost或从Teeks99Sourceforge下载。我无法使用VS2010。 在Project配置属性中将Platform Toolset更改为Visual Studio 2012(v110)。当我试图找出类似的问题时,这对我有用(#include <boost/filesystem.hpp>在VS2010最小示例代码中)。确保公共语言运行时支持设置为/clr(非/clr:pure)。