0

I've install boost 1.63.0 on Windows and I am trying to build with CMake (using Visual Studio 2017 as a generator). I'm having trouble getting find_package() to find my boost libraries and I can't figure out why.

CMakeLists.txt:

find_package(Boost REQUIRED COMPONENTS system filesystem thread)

Output:

CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.8/Modules/FindBoost.cm
ake:1813 (message):
  Unable to find the requested Boost libraries.

  Boost version: 1.63.0

  Boost include path: C:/Program Files (x86)/boost/boost_1_63_0

  Could not find the following Boost libraries:

          boost_system
          boost_filesystem
          boost_thread

  Some (but not all) of the required Boost libraries were found.  You may
  need to install these additional Boost libraries.  Alternatively, set
  BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
  to the location of Boost.

Boost finds the includes, but not the libraries. Headers are located at: %BOOST_ROOT%. Libraries are located at %BOOST_ROOT%/stage/lib. When I look at _boost_LIBRARY_SEARCH_DIRS_RELEASE, the first place it looks is the correct location. I've also tried hard-coding BOOST_LIBRARYDIR to that path just to be sure.

To install boost I extracted the downloaded archive to %BOOST_ROOT%, then ran bootstrap and .\b2 link=static,shared threading=single,multi. This should give me all versions of the libraries. In the case of boost:system, I have the following binaries in %BOOST_ROOT%/stage/lib%:

boost_system-vc100-mt-1_63.dll
boost_system-vc100-mt-1_63.lib
boost_system-vc100-mt-gd-1_63.dll
boost_system-vc100-mt-gd-1_63.lib
libboost_system-vc100-mt-1_63.lib
libboost_system-vc100-mt-gd-1_63.lib

I've tried enabling and disabling the following, but to no avail:

set( Boost_USE_STATIC_LIBS ON )
set( Boost_USE_MULTITHREADED OFF )
set( Boost_DEBUG ON )

Here is an interesting part. The Boost_DEBUG parameter spits out this line:

Searching for SYSTEM_LIBRARY_RELEASE: boost_system-vc141-mt-1_63;boost_system-vc141-mt;boost_system-mt-1_63;boost_system-mt;boost_system

Note the vc141 versus vc100. I think .\b2 built something for vc100. That's strange because I was running it from the Dev Command Prompt for VS 2017. I've taken a wild guess and tried to build boost with ./b2 toolset=msvc-14.1 but I get an error: *** argument error * rule maybe-rewrite-setup ( toolset : setup-script : setup-options : version : rewrite-setup ? )".

How can I ensure that I compile boost with VS2017 or MSVC141?

This thread seems related: Version numbers for Visual Studio 2017, Boost and CMake

Community
  • 1
  • 1
Stewart
  • 4,356
  • 2
  • 27
  • 59
  • 1
    The post you refers to suggests to build Boost with `b2 toolset=msvc-14.1` ("msvc" and version parts are delimited with **dash**, not an equal sign). – Tsyvarev May 11 '17 at 16:56
  • Found posts which suggested both ways. Tried it both ways. Thanks for the suggestion, but it didn't seem to make a difference. – Stewart May 12 '17 at 20:01

2 Answers2

0

Check the FindBoost.cmake script that is being used. Depending on the version of CMake you use, this version of Boost may not be handled. The dependencies between libraries is set depending on the version of Boost found.

For example the latest version of the script in CMake sources on GitHub handles version 1.63. I had the problem with CMake v3.6.2 which does not handle it.

Regarding the version mismatch for MSVC I don't know, sorry.

piwi
  • 5,136
  • 2
  • 24
  • 48
  • Thanks, I haven't updated cmake since 3.6.something so your answer sounds very plausible. I'll check that when I get back to work on Monday. – Stewart May 12 '17 at 20:02
  • Updated CMake to 3.8. It knows I have VS2017 installed and so it still looks for msvc-141 binaries. When I invoke boostrap & b2, it only builds msvc-100 binaries. This solution didn't work. – Stewart May 15 '17 at 07:18
0

I compiled boost, and am compiling the linking application with the same toolset. Therefore I decided that it was safe to simply rename all compiled libs from *-vc100-* to *-vc141-*. While normally I would discourage that (you could get subtle differences in the ABI), in this case I was certain that it was the same compiler and so it's clear that either cmake or b2 had a bug which created(or searched) a file with the wrong name.

After doing that, cmake not only found boost, but linked successfully.

Stewart
  • 4,356
  • 2
  • 27
  • 59
  • This worked for quite a few cases (including cases where I had linked boost::log). However, when I compiled a project with `-DUNICODE`, I get error LNK2038: mismatch detected for 'boost_log_abi': value 'v2_mt_nt5' doesn't match value 'v2_mt_nt6'. So there could still potentially be an issue. – Stewart May 23 '17 at 12:23