我无法将我的项目链接到 Microsoft Visual C++ 2008 Express Edition 中的 Boost(版本 1.37.0)文件系统 lib 文件。文件系统库是not仅标头库。我一直在关注Windows 入门 http://www.boost.org/doc/libs/1_37_0/more/getting_started/windows.html 指南发布在官方 boost 网页上。以下是我已采取的步骤:
-
我使用 bjam 构建了完整的 lib 文件集:
bjam --build-dir="C:\Program Files\boost\build-boost" --toolset=msvc --build-type=complete
我将 /libs 目录(位于 C:\Program Files\boost\build-boost\boost\bin.v2)复制到 C:\Program Files \boost\boost_1_37_0\libs。
-
在 Visual C++ 中,在项目 > 属性 > 其他库目录下,我添加了以下路径:
- C:\Program Files\boost\boost_1_37_0\libs
- C:\Program Files\boost\boost_1_37_0\libs\filesystem\build\msvc-9.0express\debug\link-static\threading-multi
出于绝望,我添加了第二个。它正是 libboost_system-vc90-mt-gd-1_37.lib 所在的目录。
-
在“配置属性”>“C/C++”>“常规”>“其他包含目录”中,我添加了以下路径:
- C:\Program Files\boost\boost_1_37_0
然后,为了锦上添花,在工具 > 选项 VC++ 目录 > 库文件下,我添加了步骤 3 中提到的相同目录。
尽管如此,当我构建项目时,我收到以下错误:
fatal error LNK1104: cannot open file 'libboost_system-vc90-mt-gd-1_37.lib'
此外,这里是我尝试编译的代码以及(假定正确的)lib 文件所在的上述目录的屏幕截图:
#include "boost/filesystem.hpp" // includes all needed Boost.Filesystem declarations
#include <iostream> // for std::cout
using boost::filesystem; // for ease of tutorial presentation;
// a namespace alias is preferred practice in real code
using namespace std;
int main()
{
cout << "Hello, world!" << endl;
return 0;
}
费鲁吉奥的回答包含了大部分的见解。然而,Pukku让我认识到了自己的错误。我发布我自己的答案以给出完整的解释。正如 Ferruccio 所解释的,文件系统依赖于两个库。对我来说,这些是:
- libboost_system-vc90-mt-gd-1_37.lib
- libboost_filesystem-vc90-mt-gd-1_37.lib
我一定没有注意到,当我提供 libboost_filesystem-vc90-mt-gd-1_37.lib 的目录时,错误输出从
fatal error LNK1104: cannot open file 'libboost_filesystem-vc90-mt-gd-1_37.lib'
to
fatal error LNK1104: cannot open file 'libboost_system-vc90-mt-gd-1_37.lib'
让我认为错误仍然存在。这导致我发布一些相当不准确的信息。另外,在读到文件系统需要两个库之后,我现在明白了关键字的重要性stage对于 bjam 命令。供应
bjam --build-dir="C:\Program Files\boost\build-boost" --toolset=msvc --build-type=complete stage
使 bjam 在 boost_1_37_0 目录中放置一个附加目录,恰当地命名为 stage。此文件夹包含一个名为 /lib 的文件夹,其中将所有 lib 文件的副本集中在一个位置。这对于 Visual C++ 来说很方便,因为您可以为其提供这个单一目录,并且它将处理所有依赖项。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)