1

Hello!

I am using Visual Studio 2017 and I recently tried to implement the Boost library in one of my projects, but that doesn't seem to be working. I always get problems with linking, and I always get the same error 1>LINK : fatal error LNK1104: cannot open file 'libboost_filesystem-vc141-mt-gd-x32-1_66.lib'. (This one was for the

#include <boost/filesystem.hpp>

code. I get the same error for all the libraries I tried to link)

I downloaded the binaries the Boost webpage offered, and installed it. I also tried adding in C/C++ > General > Additional include Directory settings the following:

C:\local\boost_1_66_0

and to the Linker > General > Additional library Directory settings I added

C:\local\boost_1_66_0\libs

And I turned off "Using Precompiled Headers". (the above were suggested by the Boost webpage)

The thread here "Linker error LNK1104 with 'libboost_filesystem-vc100-mt-s-1_49.lib'" also suggested changing my settings in C/C++ > Code Generation > Runtime Library from MT/MTd to MD/MDd which I have already done. It also said something about a bjam.exe programme, which I have not found in my boost directories, whatsoever.

Despite my tries, again LNK1104 ERROR. What should I do?

valiano
  • 16,433
  • 7
  • 64
  • 79
Cyber-Wasp
  • 49
  • 1
  • 8
  • Did you verify that `libboost_filesystem-vc141-mt-gd-x32-1_66.lib` exists in the folder you have added to your Additional library Directorys? – drescherjm Dec 30 '17 at 22:37
  • @drescherjm everything but the bjam.exe – Cyber-Wasp Dec 30 '17 at 22:39
  • So `libboost_filesystem-vc141-mt-gd-x32-1_66.lib` does exist? Your reply does not seem that you verified the exact file name. – drescherjm Dec 30 '17 at 22:39
  • Oh, I see my mistake. I need the 32 bit folder, not the 64 one.... I actually installed the 64 one -_-. The files exist, but not the 32 bit ones. In my build I have "libboost_filesystem-vc141-mt-gd-x64-1_66.lib", not "libboost_filesystem-vc141-mt-gd-x32-1_66.lib" – Cyber-Wasp Dec 30 '17 at 22:43
  • @drescherjm Again, I downloaded the 32 bit version, but again the same error! – Cyber-Wasp Dec 30 '17 at 23:28
  • 1
    Well at this point, unless someone can see what you're actually doing, I don't see a resolution to this issue except to tell you "you're doing something wrong". I have used VS 2017 and boost with absolutely no issues. The Additional Library Directory is set correctly, header file include set correctly, and no issues. – PaulMcKenzie Dec 30 '17 at 23:58
  • Maybe you did not set these settings for every configuration. Remember the settings for each configuration is independent. – drescherjm Dec 31 '17 at 00:05
  • No, didn't fix the error – Cyber-Wasp Dec 31 '17 at 11:46
  • @drescherjm I am really sorry to be a bother! I was indeed wrong. At first glance the files I had and the ones the compiler asked for seemed identical. However, I had libboost_filesystem-vc**140**-mt-gd-x32-1_66.lib not libboost_filesystem-vc**141**-mt-gd-x32-1_66.lib. – Cyber-Wasp Dec 31 '17 at 15:22
  • The `vc140` versions are for Visual Studio 2015. – drescherjm Dec 31 '17 at 15:25
  • I am really dumb. Thank you again for your help and sorry for being a bother :D – Cyber-Wasp Dec 31 '17 at 15:26
  • I think it is a little confusing when the difference is between `vc140` and `vc141` in a long string. – drescherjm Dec 31 '17 at 15:39

2 Answers2

3

Since Visual Studio is both a 32 bit and a 64 bit compiler, there are no less than 16 different types of a library that you can link with it, i.e. the combinations of:

  • 32 bit or 64 bit,
  • shared or static library,
  • debug or release
  • and single or multi threaded.

Also, since there are different version of both boost and Visual Studio, there are potentially many more combinations than the 16 above! Fortunately, boost supports auto linking with Visual Studio, see: How Boost automatically includes libraries. So the filename in your linker error gives some clues as to precisely what type of boost library Visual Studio is searching for:

LINK : fatal error LNK1104: cannot open file 'libboost_filesystem-vc141-mt-gd-x32-1_66.lib'

According to the answers here: How can I decode the boost library naming? , Visual Studio is searching for multi-threaded, debug version of the boost 1.66 filesystem library.

I also know from experience that Visual Studio static libraries start with libboost_ while shared libraries start with boost_ and someone changed the boost naming system in boost 1.66 to add the size to the name (-x32 or -x64), causing no end of trouble to existing build systems, e.g. CMake!

So Visual Studio is still searching for a static, 32 bit version of boost::filesystem, despite changing your settings...

To fix it, either download the 32 bit static libraries or build your own boost libraries by following the instructions here: Building boost for Visual Studio.

Note: regardless which option you choose, you'll still get the compiler warning:

Unknown compiler version - please run the configure tests and report the results

because, the current version of Visual Studio was released afterboost 1.66.
This is a common warning when using older versions of boost with newer compilers.

kenba
  • 4,303
  • 1
  • 23
  • 40
  • Thank you very much. I thought I downloaded the correct version, but I had version 14.0, not 14.1 (I had libboost_filesystem-vc140-mt-gd-x32-1_66.lib not libboost_filesystem-vc141-mt-gd-x32-1_66.lib). I also built it to make sure it operates properly and it works fine. – Cyber-Wasp Dec 31 '17 at 15:20
1

Instead of adding the \libs directory to the library paths add the \lib64-msvc-14.1 directory.

SoronelHaetir
  • 14,104
  • 1
  • 12
  • 23
  • Did you add it for the correct configuration? Win32 (x86) builds need the lib32-msvc-14.1 directory while win64 builds need lib64-msvc-14.1. Personally I suggest making these changes under the view->Other windows->Property manager window. That way they will be present for all projects you want to build. – SoronelHaetir Dec 31 '17 at 00:04