103

Seem I can't get this to work. I made a simple console application (which depend on websocket++ library) which need Boost libraries.. but when I try to compile I get:

fatal error LNK1104: cannot open file 'libboost_system-vc110-mt-gd-1_51.lib'

However, I did the bjam which created the lib in (boost_root)/stage/libs and I linked the path to the libs to the compiler C++/Additionnals includes.

If I look in (boost_root)/stage/libs the file libboost_system-vc110-mt-gd-1_51.lib is not there. It is called libboost_system-vc110-mt-sgd-1_51.lib instead.

Any idea?

5
  • 1
    Ive been able to build the libboost_system-vc110-mt-gd-1_51.lib file doing a complete build with bjam however i still get the error.
    – Rushino
    Oct 24, 2012 at 3:38
  • 26
    Open the VS2012 developer command prompt, go to your boost root directory and type bootstrap, and then type b2 and you should get a complete set of library files.
    – Jesse Good
    Oct 24, 2012 at 3:39
  • Did you add the include paths and linker paths to your project?
    – Jesse Good
    Oct 24, 2012 at 3:40
  • 1
    Are you building your application with /MD ?
    – Mahesh
    Oct 24, 2012 at 3:45
  • If it's okay to download instead of compile, get the libs from here: code.ingres.com/boostlib/trunk/stage/lib
    – gorogm
    Apr 21, 2013 at 11:20

12 Answers 12

119

This is the simplest way for an amateur like me who is studying C++ on their own:

First Unzip the boost library to any directory of your choice. I recommend c:\directory.

  1. Open your visual C++.
  2. Create a new project.
  3. Right click on the project.
  4. Click on property.
  5. Click on C/C++.
  6. Click on general.
  7. Select additional include library.
  8. Include the library destination. e.g. c:\boost_1_57_0.
  9. Click on pre-compiler header.
  10. Click on create/use pre-compiled header.
  11. Select not using pre-compiled header.

Then go over to the link library were you experienced your problems.

  1. Go to were the extracted file was c:\boost_1_57_0.
  2. Click on booststrap.bat (don't bother to type on the command window just wait and don't close the window that is the place I had my problem that took me two weeks to solve. After a while the booststrap will run and produce the same file, but now with two different names: b2, and bjam.
  3. Click on b2 and wait it to run.
  4. Click on bjam and wait it to run. Then a folder will be produce called stage.
  5. Right click on the project.
  6. Click on property.
  7. Click on linker.
  8. Click on general.
  9. Click on include additional library directory.
  10. Select the part of the library e.g. c:\boost_1_57_0\stage\lib.

And you are good to go!

6
  • 4
    Thanks very much Wu Jie - I had never done anything like this before and these steps were exactly what I needed to build Boost and produce the missing 'libboost_serialization-vc140-mt-gd-1_57.lib' library file I was having trouble linking :)
    – Vixxd
    Apr 16, 2015 at 0:36
  • 7
    Thanks, I like nice detailed instructions. For step 2/3/4 of setting up boost, what I instead did was: a) open a commandline prompt as root; b) change to the boost_1_57_0 directory; c) type bootstrap.bat (it took 10-20 seconds); d) type ./b2 as instructed (it then took 30-40 minutes to complete). Mar 25, 2016 at 12:28
  • 3
    I had to open bootstrap.bat using the Visual Studio command prompt, as the regular command prompt did not know how to process the 'cl' command.
    – jlaverde
    Nov 3, 2017 at 16:42
  • 2/20/2018, your solution works for me (VS2017 + Boost 1.66). Thank you so much.
    – CaTx
    Feb 20, 2018 at 22:57
  • Thank you for the steps for beginners. I wish everyone would always give answers like you have given.
    – Mudit Jain
    Mar 25, 2018 at 16:50
99

The C++ → General → Additional Include Directories parameter is for listing directories where the compiler will search for header files.

You need to tell the linker where to look for libraries to link to. To access this setting, right-click on the project name in the Solution Explorer window, then Properties → Linker → General → Additional Library Directories. Enter <boost_path>\stage\lib here (this is the path where the libraries are located if you build Boost using default options).

8
  • can u explain me what is the boost_path
    – ggsmartboy
    Feb 13, 2013 at 11:25
  • 1
    @ggsmartboy It's the path where the boost source files are (the same path that you list in the compiler include paths so it can find the boost headers). The answer assumes that you built boost yourself (not using a distribution) using the default build options.
    – Praetorian
    Feb 13, 2013 at 15:00
  • 2
    The settings referred to in this answer are found if you right click on the project and choose properties (for noobs like me, right clicking the solution, going to Tools > Options etc. Those options were not present on all my projects though). VS2013 Apr 22, 2015 at 20:22
  • 1
    @Mr_and_Mrs_D You're right, I did assume the reader knew that part. Updated.
    – Praetorian
    Apr 23, 2015 at 5:20
  • 1
    Well, i don't have folder "stage" in boost 1.64
    – Archont
    Dec 10, 2017 at 4:47
8

Yet another solution:

I was stumped because I was including boost_regex-vc120-mt-gd-1_58.lib in my Link->Additional Dependencies property, but the link kept telling me it couldn't open libboost_regex-vc120-mt-gd-1_58.lib (note the lib prefix). I didn't specify libboost_regex-vc120-mt-gd-1_58.lib.

I was trying to use (and had built) the boost dynamic libraries (.dlls) but did not have the BOOST_ALL_DYN_LINK macro defined. Apparently there are hints in the compile to include a library, and without BOOST_ALL_DYN_LINK it looks for the static library (with the lib prefix), not the dynamic library (without a lib prefix).

1
  • Still only 1 upvote, yet I find myself here every few months, being reminded again what the solution is to my problem!! Oct 26, 2017 at 8:52
6

I had the same problem. It was caused because I compiled the Boost with the Visual C++ 2010(v100) and I tried to use the library with the Visual Studio 2012 (v110) by mistake.

So, I changed the configurations (in Visual Studio 2012) going to Project properties -> General -> Plataform Toolset and change the value from Visual Studio 2012 (v110) to Visual Studio 2010 (v100).

2
  • 7
    I hope you realize that when you change the platform toolset to use v100, you're telling the VS2012 IDE to use the compiler that shipped with VS2010. Any C++11 features that were added to the VS2012 compiler will not be available. A better solution is to compile Boost using the VS2012 compiler; you can have the generated libraries from both 2010 and 2012 co-exist because Boost puts the compiler version number into the output filenames.
    – Praetorian
    Mar 7, 2013 at 18:55
  • You're right and I'm aware. I afraid of what might happen if I upgrade the libraries and the compiler. So, when the project is finished I will fix all this stuff. Thanks! Mar 16, 2013 at 21:31
3

I had the same problem and my mistake was that I had installed the binary boost_1_55_0-msvc-11.0-32.exe to use with visual c++ 2010 which has the version v100 (project properties->ConfiguratioProperties->General->platformTooset) not v110 as visual c++ 2012. So I dowloaded boost_1_55_0-msvc-10.0-32.exe and now everything is ok so far.

3

I had a similar problem when trying to use boost unit testing in Visual Studio 2015 (Community Edition):

fatal error LNK1104: libboost_unit_test_framework-vc140-mt-1_57

so I thought I'd share my solution.

You can create a boost unit testing project in of of two ways (and this solution works for both):

  1. using the Boost Unit Test Adapter
  2. or by creating a Win32 Console Application (steps here), and substituting the main function with a boost unit testing function (steps here).

Here are the steps I followed to get both projects to work:

First, download the desired boost version (for example, boost_1_57_0). You can either download boost with the correct binaries (compiled using msvc v140), or extract the binaries yourself by running the following commands from command line:

  1. bootstrap.bat
  2. "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86
  3. bjam --clean
  4. bjam -j4 --debug-symbols=on --build-type=complete toolset=msvc-14.0 threading=multi runtime-link=shared address-model=32

Where msvc-14.0 specifies that we require the Visual Studio 2015 version (VS 2015 = v14.0 = v140), and address-model=32 specifies that we require platform 32 (but the same can be done for 64 bit).

Once you have the binaries, go to Visual Studio, select the Boost Unit Testing project you have created. Go to Project properties > configuration (from the main menu) and make the following choices:

  • Set the "General > Platform Toolset" to Visual Studio 2015 (v140).

  • Include the path to the boost folder (e.g. C:\boost_1_57_0) and the path to the subfolder containing the binary files (e.g. C:\boost_1_57_0\stage\lib) in:

    • "C\C++ > Additional Include Directory"
    • and "Linker > Additional Library Directories".
2

In case you have trouble building boost or prefer not to do that, an alternative is to download the lib files from SourceForge. The link will take you to a folder of zipped lib and dll files for version 1.51. But, you should be able to edit the link to specify the version of choice. Apparently the installer from BoostPro has some issues.

2

b2 -j%cores% toolset=%msvcver% address-model=64 architecture=x86 link=static threading=multi runtime-link=shared --build-type=minimal stage --stagedir=stage/x64

Properties → Linker → General → Additional Library Directories $(BOOST)\stage\x64\lib

1
  • A bit more elaboration on what are those lines doing and why -> would help to improve the quality of this answer. Jun 25, 2019 at 18:57
1

If you are using Visual Studio, have you tried using Tools / NuGet Package Manager to install boost_program_options-vcXXX? This is an easy way of installing boost.

0

I had same issue reported here. I solved the issue moving the mainTest.cpp from a subfolder src/mainTest/ to the main folder src/ I guess this was your problem too.

0

2>LINK : fatal error LNK1104: cannot open file 'libboost_regex-vc120-mt-sgd-1_55.lib

In my case, bootstrap/bjam was not available (libraries were precompiled and committed to SCM) on old inherited project. Libraries did not have VC or BOOST versioning in their filenames eg: libboost_regex-mt-sgd.lib, however Processed /DEFAULTLIB:libboost_regex-vc120-mt-sgd-1_55.lib was somehow triggered automatically.

Fixed by manually adding the non-versioned filename to:

<AdditionalDependencies>$(DK_BOOST)\lib64\libboost_regex-mt-sgd.lib</AdditionalDependencies>

and blacklisting the ...vc120-mt-sgd-1_55.lib in

<IgnoreSpecificDefaultLibraries>libboost_regex-vc120-mt-sgd-1_55.lib</IgnoreSpecificDefaultLibraries>
0

I had the similar error on my Visual Studio 2012 with boost 1.60: fatal error LNK1104: cannot open file 'libboost_filesystem-vc110-mt-gd-1_60.lib'

I fixed this issue by downloading boost binaries:

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.