10

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;
}
Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
Scott
  • 2,551
  • 5
  • 25
  • 25

7 Answers7

8

Ferruccio's answer contains most of the insight. However, Pukku made me realize my mistake. I am posting my own answer to give a full explanation. As Ferruccio explained, Filesystem relies on two libraries. For me, these are:

  • libboost_system-vc90-mt-gd-1_37.lib
  • libboost_filesystem-vc90-mt-gd-1_37.lib

I must not have noticed that when I supplied the directory for libboost_filesystem-vc90-mt-gd-1_37.lib, the error output changed from

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'

Causing me to think that the error was persisting. This lead me to post some rather inaccurate information. Also, after reading that Filesystem requires two libraries, I now see the significance of the keyword stage for the bjam command. Supplying

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

Causes bjam to place an additional directory, aptly named stage, in the boost_1_37_0 directory. This folder contains a folder named /lib, which has copies of all of the lib files in one place. This is convenient for Visual C++ because you can supply it with this single directory and it will take care of all of the dependencies.

Scott
  • 2,551
  • 5
  • 25
  • 25
  • I see. I always build with the install keyword instead of stage, the results are different. – Ferruccio Jan 23 '09 at 01:19
  • Ok, I need some help here - I have the same problem (i'm using the same command as you specified) - but the file I'm getting is: boost_system-vc90-mt-gd-1_44.lib and not 'libboost_system-vc90-mt-gd-1_44.lib'. (I'm using a later version of boost, but my file names don't have the needed 'lib' in front of them). My compiler keeps asking for 'libboost_system-vc90-mt-gd-1_44.lib'. – sparkFinder Nov 26 '10 at 02:36
  • @sparkFinder bjam's command line option `stage` makes bjam to put all built libraries into `boost_M_mm_b\stage\lib`. Both `boost_system-vc90-mt-gd-M_mm.lib` and `libboost_system-vc90-mt-gd-M_mm.lib` should be there (M, mm and b are just generic symbols for major, minor and build version for Boost) – Bojan Komazec Jan 29 '11 at 20:43
3

boost::filesystem is dependent on boost::system, so you need both paths.

Part of the problem is you're using the boost libs out of the build directories instead of the install directory (the boost build process should create both). The install/lib directory has all the libs so you only need to specify one path.

The boost build process builds each library in its own directory. At the end it copies all those .lib files into one common lib directory.

Since you didn't specify an install directory as part of your build command (with --prefix=...), I believe the default is C:\Boost. Check to see if that directory is there and if so use C:\boost\include\ boost-1_37 for your include path and C:\boost\lib for your library path.

Ferruccio
  • 98,941
  • 38
  • 226
  • 299
  • Are you talking about the bjam command? I did supply a directory. I have no directory called "C:\boost." I copied the /libs directory generated in the specified "build-boost" directory to the existing /libs directory under boost_1_37_0. – Scott Jan 22 '09 at 22:35
  • You were right about it needing the system lib though. I commented about this in Pukku's answer. I misread system as filesystem. So, it needs both? Perhaps this is why I got confused. However, I thought I removed the path to the filesystem lib when I replaced it with the system lib. I will... – Scott Jan 22 '09 at 22:36
2

Last answer is right. But you should find boost config file $BOOST\config\user.hpp and uncomment this directive #define BOOST_ALL_DYN_LINK. Now it begin use dynamic link with boost and it should works.

dvsdimas
  • 21
  • 2
  • 2
    Welcome to Stack overflow. Be aware that answers are resorted as votes are cast, so when you write "last answer," it's not clear which answer you mean. – David Gorsline Apr 24 '12 at 23:41
2

I think the real original problem is related to the default boost build process on windows which expects static linking of a library which will have a name beginning libboost_sytem<etc..>. The macro you need is

#define BOOST_SYSTEM_DYN_LINK

which makes ensures that the Boost.System library is dynamically linked. The dynamic library name is boost_system<etc...> as apposed the the static library libboost_sytem<etc...>

Enamul Hassan
  • 5,266
  • 23
  • 39
  • 56
david
  • 21
  • 1
1

I had this same problem, what you need to do is add the "lib" directory under the top level boost folder to the library path in Visual C++.

This most definitely solved the issue for me.

Tyler Brock
  • 29,626
  • 15
  • 79
  • 79
  • Yes. This fixed it for me as well. I had to copy "libboost_unit_test_framework-vc90-mt-1_43.lib" and "libboost_unit_test_framework-vc90-mt-gd-1_43.lib" into the "lib" subdirectory in the QuantLib directory (thats the only one it needs). I also had to copy the header files over in directory "boost" to stop it complaining about missing header files. For some reason, I also had to change the build to "Debug" (from "Debug (static)") because I did not have the -sgd- libraries built by default. – Contango Sep 08 '10 at 18:28
1

The error you have posted complains about file libboost_system-vc90-mt-gd-1_37.lib, but in the directory you have only libboost_filesystem-vc90-mt-gd-1_37.lib, right?

Look for libboost_system-vc90-mt-gd-1_37.lib. If you find it, add the corresponding directory to the library search path. If you don't find it, see if you have boost_system-vc90-mt-gd-1_37.lib instead (like I do), and try copying that to the desired filename.

Reunanen
  • 7,921
  • 2
  • 35
  • 57
  • Yes, I do have libboost_system-vc90-mt-gd-1_37.lib. As I said, it is located in C:\Program Files\boost\boost_1_37_0\libs\filesystem\build\msvc-9.0express\debug\link-static\threading-multi. – Scott Jan 22 '09 at 21:27
  • Well, you did not really say that you do have a file with this specific name. But ok, it's something else then... – Reunanen Jan 22 '09 at 21:29
  • I'm sorry for the lack of clarity. This is what I meant when I said "It is the exact directory that the lib file resides in," yet I suppose it wasn't until later in the post that I named the file that the linker was looking for. – Scott Jan 22 '09 at 21:36
  • I believe link-static should end up with sgd in the file name, but you have just gd. However, I cannot tell how this could help :( – Reunanen Jan 22 '09 at 21:43
  • I added a screen shot of the directory. – Scott Jan 22 '09 at 21:50
  • You were right! I misread the directory listed in the "Search Results" in Windows. The file is actually located in C:\Program Files\boost\boost_1_37_0\libs\system\build\msvc-9.0express\debug\link-static\threading-multi! This caused me to accidentally lie about where the file resided. – Scott Jan 22 '09 at 22:24
  • The screen shot reveals my mistake. I added the correct directory and the project links as expected! Doh! Thank you. – Scott Jan 22 '09 at 22:24
  • I guess my intuition caused my to see filesystem rather than system. After all, filesystem seems like the most appropriate directory. – Scott Jan 22 '09 at 22:26
  • Seeing as how this is just a silly mistake, should I delete this topic? If not, should I modify my post to correct the misinformation? After all, the post is more misleading than helpful. – Scott Jan 22 '09 at 22:27
  • I would probably close as not relevant anymore. – Reunanen Jan 23 '09 at 05:04
1

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?

gimpf
  • 4,503
  • 1
  • 27
  • 40
  • I am aware of the additional stage keyword. I opted to leave this out of my question, for when I used this, it simply created a directory called stage in C:\Program Files\boost\boost_1_37_0. The directory contained a folder called lib, which contained a bunch of the... – Scott Jan 22 '09 at 21:32
  • ...same lib files. Perhaps I should tell Visual C++ to look in this directory? As far as I can tell, these are the same lib files that were located in C:\Program Files\boost\build-boost\boost\bin.v2\libs. – Scott Jan 22 '09 at 21:33
  • 1
    Ah! Now I see your point. I was unaware that Filesystem relied on multiple libraries and now see the convenience of the stage/lib directory. These are, in fact, copies of all of lib files located in one place for convenience's sake. Thank you. I'm sorry I misunderstood you to begin with. – Scott Jan 22 '09 at 22:59