How do I resolve LNK1104 error with Boost Filesyst

2019-03-11 07:24发布

I am having trouble getting my project to link to the Boost (version 1.37.0) Filesystem lib file in Microsoft Visual C++ 2008 Express Edition. The Filesystem library is not a header-only library. I have been following the Getting Started on Windows guide posted on the official boost web page. Here are the steps I have taken:

  1. I used bjam to build the complete set of lib files using:

    bjam --build-dir="C:\Program Files\boost\build-boost" --toolset=msvc --build-type=complete
    
  2. I copied the /libs directory (located in C:\Program Files\boost\build-boost\boost\bin.v2) to C:\Program Files\boost\boost_1_37_0\libs.

  3. In Visual C++, under Project > Properties > Additional Library Directories I added these paths:

    • 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

    I added the second one out of desperation. It is the exact directory where libboost_system-vc90-mt-gd-1_37.lib resides.

  4. In Configuration Properties > C/C++ > General > Additional Include Directories I added the following path:

    • C:\Program Files\boost\boost_1_37_0
  5. Then, to put the icing on the cake, under Tools > Options VC++ Directories > Library files, I added the same directories mentioned in step 3.

Despite all this, when I build my project I get the following error:

fatal error LNK1104: cannot open file 'libboost_system-vc90-mt-gd-1_37.lib'

Additionally, here is the code that I am attempting to compile as well as a screen shot of the aformentioned directory where the (assumedly correct) lib file resides:

#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;
}

7条回答
成全新的幸福
2楼-- · 2019-03-11 07:54

The bjam command line should have built all versions of all libraries. Still, when you build with

bjam --build-dir="C:\Program Files\boost\build-boost" --toolset=msvc --build-type=complete stage

(note the stage at the end) all libraries are copied to a common libs/ folder, so that MSVC's autolinking feature works when you only add this libs/ folder to your library path.

I do not know if bjam without stage still copies all those files to a single folder. If not, execute such a stage build to do this. If they are, well, sorry, configuration seems correct, maybe a minor typing error somewhere?

查看更多
登录 后发表回答