1

vs2015 community, x64, debug, boost 1.63

  • New Empty project
  • Properties->C++->General->Additional Include Directories add "C:\Program Files\boost_1_63_0" Add new C++ file, Source.cpp:
#include "boost/make_shared.hpp"   
#include "boost/thread.hpp"

void main(int argc, char **argv)
{
}
  • Build Solution
  • Result:
1>------ Build started: Project: boostLibTest, Configuration: Debug x64 ------
1>  Source.cpp
1>LINK : fatal error LNK1104: cannot open file 'libboost_thread-vc140-mt-gd-1_63.lib'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Where is that lib file getting added to the project? It's not boostLibTest.vcxproj, nor the command line for the compiler.

I wanted to write a static library that uses boost that I can access from another app that doesn't have/need boost, but this auto-include-boost-dependency prevents me from doing so.

wally
  • 10,717
  • 5
  • 39
  • 72
SolarisPol
  • 103
  • 8
  • 1
    The Boost headers contain pragmas to tell the linker what libraries to link. https://msdn.microsoft.com/en-us/library/7f0aews7.aspx, http://www.boost.org/doc/libs/1_63_0/boost/config/auto_link.hpp – Jerry Coffin Mar 07 '17 at 22:08
  • http://stackoverflow.com/q/5184889/1460794 – wally Mar 07 '17 at 22:17
  • Yikes! didn't know pragmas could do that :\ ... I can ask it as a separate question, but in my static library example, even if I provide the boost library in the static library, the separate app that doesn't need/use boost still asks for that boost library. – SolarisPol Mar 07 '17 at 22:18
  • Something must have made the separate app think it needed the boost libraries. Are you sure a boost header isn't perhaps indirectly included? – wally Mar 07 '17 at 22:23
  • If you don't want it autolinking, then why don't you simply [disable that feature](http://stackoverflow.com/a/4739745/3962537)? – Dan Mašek Mar 07 '17 at 23:34

1 Answers1

2

There are #pragmas that MSVC supports that let a header file state "you need this library".

Boost is apparently using them.

Ideally, boost should only include them in header files that are not "header only". The granularity may not be perfect. But if you only need some enum values and other header-file only data from "boost/thread.hpp", check to see if they are included in a "header-file-only" header.

Yakk - Adam Nevraumont
  • 262,606
  • 27
  • 330
  • 524