0

I'm trying to compile Boost as shared libraries and make them a dependency of my cross platform CMake project.

For that, I compiled boost for win32, x64 and linux where my boost folder structure looks like:

- boost_1_69_0/
  - boost/
  - stage/
    - win32
      - lib
    - x64
      - lib
    - linux
      - lib

Then I'm doing:

set(BOOST_INCLUDEDIR ${CMAKE_CURRENT_SOURCE_DIR}/../external/boost_1_69_0)
set(BOOST_LIBRARYDIR ${CMAKE_CURRENT_SOURCE_DIR}/../external/boost_1_69_0/stage/win32)
find_package(Boost REQUIRED COMPONENTS filesystem)

And getting:

CMake Error at C:/Program Files/CMake/share/cmake-3.13/Modules/FindBoost.cmake:2100 (message):
Unable to find the requested Boost libraries.

Boost version: 1.69.0

Boost include path: C:/bla/SW/cmake-template/external/boost_1_69_0

Could not find the following Boost libraries:

        boost_filesystem

Is that a bug?


If I move the lib folder from inside win32 to it's parent directory, i.e:

- boost_1_69_0/
  - boost/
  - stage/
    - lib

which is the default way boost's b2 build stuff, then it's all working. But then I can't hold different boost binaries for different platforms.


EDIT:

using set(Boost_DEBUG ON) I found out my boost is compiled with Visual Studio v141 toolset while my project is using v140, and so FindBoost is looking for boost_filesystem-vc140-mt-x64-1_69 and not boost_filesystem-vc140-mt-x64-1_69.

I guess the problem has shifted to either find a way to force searching for v141 or (better) use --layout=system and find a way to force it to always look for boost_filesystem. Is there a way of doing that?

galah92
  • 3,621
  • 2
  • 29
  • 55
  • Have a look at the library directory, is there a `boost_filesystem.dll` or `boost_filesystem.lib`? – Stanley F. Apr 17 '19 at 08:11
  • @StanleyF. there's `boost_filesystem-vc141-mt-x32-1_69.dll` & `boost_filesystem-vc141-mt-x32-1_69.lib` – galah92 Apr 17 '19 at 08:12
  • *Library directory* (what BOOST_LIBRARYDIR should be assigned to) is a directory which **immediately** contains libraries. In your case, this is a directory `external/boost_1_69_0/stage/win32/lib` (ended with **lib**). BTW, you may always check which **actual paths are searched** by `find_package(Boost)` with setting `Boost_DEBUG` variable to TRUE. – Tsyvarev Apr 17 '19 at 08:25

1 Answers1

1

The problem here is that CMake searches for boost libraries matching a certain naming scheme. Your libraries differ from that, since there are some options encoded within the filename. You have two options:

  1. Compile boost again but this time with --layout=system flag when running the b2 executable. This will create library files with standard names like boost_filesystem.dll and boost_filesystem.lib.
  2. Give CMake some hints on how your library files are named, using the following variables dedicated to boost variants (since I don't have an equivalent system like yours, those are guesses, which you may have to adopt):
    • Boost_ARCHITECTURE="-x32"
    • Boost_COMPILER="-vc141"
Stanley F.
  • 1,846
  • 16
  • 29
  • Thanks, `Boost_COMPILER` did solve it! Is there a way to hind `FindBoost` to search for `--layout=system` on Windows as well? because it always looks to the default Windows layout. – galah92 Apr 17 '19 at 09:05
  • Currently, `FindCmake` breaks for Windows if `layout=system` was used because it only looks for `boost_filesystem-vc140-mt-x64-1_69` and not for `boost_filesystem`. My question is whether it is possible to make it work, using a hidden flag or something like that. – galah92 Apr 17 '19 at 11:35
  • @galah92 Actually, boost *is* looking for `boost_filesystem`, as explained in [this answer](https://stackoverflow.com/a/13281373/579698). So with `layout=system` everything should work out of the box. Without `layout=system` you need to specify the naming scheme as point 2 in my answer outlines. – Stanley F. Apr 17 '19 at 11:58