Boost linking, Visual Studio & version control

2020-04-07 12:31发布

问题:

I'm using Visual Studio 2008, and writing some stuff in C++. I'm using a Boost library (that is not header only).

So, linking to Boost requires one to add the directory to Boost binaries to the project's "additional linker paths" setting.

However, doesn't this conflict with source control? If I check in the project files, wouldn't the absolute path to Boost libs on my computer also be included in them?

I obviously don't want this to happen, so what should I do? Just adding the Boost directory to "Visual C++ Directories/Libraries" doesn't work.

回答1:

Adding the Boost paths to "Visual C++ Directories" should work. You should add include path <Full path here>\boost_1_39_0 (no boost at the end)
and library path <Full path here>\boost_1_39_0\bin.v2\lib (bin.v2 is a stage dir that could be different in you case).

Personally, I store boost sources in my source control and use relative paths in project settings.



回答2:

We use a repository containing 3rd party libraries, then use svn:externals to checkout the required parts into the project's base directory, finally use relative paths for additional include and library directories in the project file. Works well, only disadvantage is that you can end up with several boost copies on your harddisk. Using junctions (Windows' version of symbolic links for directories only, works at least from Win2k on, not sure about NT) you can get rid of the wasted space.



回答3:

We put all our 3rdparty headers and libraries used by a project in the project tree in source control. This means we track the version of the libraries with the source.

Then we reference the include and source directories in the project properties. We do not use the Visual C++ Directories as this puts too much dependence on the location of files on different developers systems and also the versions of libraries cannot be tracked.

The only exception to this would be the platform sdk when developing with vc6.

Shameless plug: We now manage our vc project settings with CMake and it make these things much easier esp for large projects.



回答4:

You tell VS about Boost in a per-computer fashion, not a per-project fashion. Just like directx and other libraries that are not project specific. We think it's reasonable to assume that boost is used in more than one project.

We don't track external library source in our project SCM unless we're intimate with the implementation details (patching it or whatever). For boost, directx, windows sdk, we just require you to run the respective installer and set the VC++ Directories when you set up your dev environment.



回答5:

I use the BOOST_ROOT environment variable for some stuff, and it works OK. You have to manually create it, and then set the paths in the project files as "$(BOOST_ROOT)\include" and "$(BOOST_ROOT)\lib" (or whatever your layout uses). Everyone then has to set BOOST_ROOT on their machines to point to their Boost install.