2

我不是一个有经验的程序员。我尝试剪切部分 boost 并将其直接粘贴到我的项目中,这是 Visual Studio 2010 中的 C++ 解决方案。我是这样做的:

  • 解压boost库
  • bootstrap.bat
  • bjam tools/bcd- 这创建了目录.\bin.v2\tools\bcp\msvc-10.0\release\link-static\threading-multi\
  • 将目录更改为上述
  • 我写了一个脚本来扫描解决方案中的所有文件,结果是:
    noncopyable static_assert ratio thread/locks thread chrono interprocess/mapped_region thread/recursive_mutex crc cstdint interprocess/file_mapping make_shared shared_ptr lexical_cast
  • bcp --boost=C:\Users\xxxxxxxx\boost_1_49_0 noncopyable static_assert ratio thread/locks thread chrono interprocess/mapped_region thread/recursive_mutex crc cstdint interprocess/file_mapping make_shared shared_ptr lexical_cast lexical_cast ./myboost
  • 将./myboost复制到解决方案中,设置属性,一切正常,直到我不尝试 #include "boost/chrono.hpp" (例如 #include "boost/lexical_cast.hpp" 没问题)。
  • boost/chrono.hpp 导致链接器错误:

    3>playerMain.obj : 错误 LNK2001: 无法解析的外部符号 "class boost::system::error_category const & __cdecl boost::system::system_category(void)" (?system_category@system@boost@@YAABVerror_category@12@XZ)

    3>playerMain.obj : 错误 LNK2001: 无法解析的外部符号 "class boost::system::error_category const & __cdecl boost::system::generic_category(void)" (?generic_category@system@boost@@YAABVerror_category@12@XZ)


我是否正确使用 bcp?
我应该怎么做才能让它工作?

4

1 回答 1

3

安装 Boost 以与 Visual Studio 一起使用的过程在这里非常清楚地说明。您不需要编写任何安装脚本。

重要的是要知道大多数 Boost 库是仅头文件(例如 Boost.Lexical_Cast),但有些需要您链接到静态库(例如 Boost.System)。请参阅入门文档的这一部分,了解如何让 Visual Studio 知道 Boost 静态库的位置。

列出了哪些库不是仅标头。一些库(例如 Boost.Chrono 和 Boost.Asio)本身是只有头文件的,但它们取决于Boost.System哪些需要链接到您的程序中。

希望这可以帮助。

于 2012-03-10T23:25:50.207 回答