Boost logo

Boost Users :

Subject: Re: [Boost-users] linking and including in visual studio
From: David Medine (dmedine_at_[hidden])
Date: 2016-04-28 14:04:24

On 4/27/2016 9:42 PM, Gavin Lambert wrote:
> On 27/04/2016 08:14, David Medine wrote:
>> Having learned to write and compile C++ code on Linux, I am always in
>> the habit of explicitly stating the include and library paths for the
>> compiler to search for, as well as the libraries themselves that need to
>> be linked. However, I am revising some Visual Studio projects that use
>> boost and I realized that the path I gave for 'Additional Library
>> Directories' is $(BOOST_ROOT)/lib, but my version of boost hasn't got
>> this directory (it's actually $(BOOST_ROOT)\libs). I then removed all
>> references to boost from 'Additional Library Directories', and
>> 'Additional Include Directories' and the application builds and runs
>> swimmingly.
>> This leads me to believe, that assigning the BOOST_ROOT environment
>> variable in Windows is the only step that is needed for VS's auto
>> linking magic to link correctly to boost. Am I right here, or is there
>> something I am missing?
> No, there has to be something somewhere supplying the include and
> library paths.
> What VS does have (and GCC does not) is auto-linking, which merely
> allows you to avoid having to explicitly specify the names of the
> Boost libraries to link with. But this is just the names, not the paths.
> There are many places that library paths can hide, however; they can
> include:
> * the project settings
> * property sheets imported by the project
> * the LIBPATH environment variable
> * Tools -> Options -> Projects and Solutions -> VC++ Directories (on
> older versions of VS) or the Microsoft.Win32.Cpp.user.props sheet (on
> newer versions of VS)
> There might even be a few more than I'm unaware of. :)

Thanks for this (and to everyone else contributing to this discussion!)

For now, I can say with certainty that:
1. there is no reference to boost in the property settings of the project,
2. I'm not using any inherited property sheets,
3. there is no reference to boost in any of my Windows environment
variables apart from BOOST_ROOT, and
4. there is no reference to boost in Tools -> Options -> Projects and
Solutions -> VC++ Directories.

I've attached a buidlog and if you open it and search for 'boost' you
will see that there is indeed no reference in the build commands; and
yet, if I rename the directory pointed to by BOOST_ROOT, the build will
fail to find the boost headers included in the source code. All of
which, again, leads me to believe that (unless I am still missing some
evil little arcane setting in VS that is working behind my back) setting
BOOST_ROOT is all Windows + VS (I'm using 2008 by the way) needs in
order to include boost headers and link to the libraries.

What I assume is happening is that BOOST_ROOT is a special environment
variable that Windows knows about and, if it is defined, Windows will
put the correct directories on the global include search paths. Then,
based on what headers get included, the autolinker will know what are
the right libraries to link with and where to find them (e.g. if you
include <boost/thread.hpp> it will automagically know to link to
boost_thread-vc90-mt-1_57.lib or whatever the appropriately suffixed
binary is).

A way to test this is to set up a fresh Windows machine with no
environment variables defined, install VS, get the desired version of
boost, and try to build before and after setting BOOST_ROOT. If it works
after those steps alone, then it works after those steps alone.

> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at