简体   繁体   中英

find_package(Boost) error when BOOST_INCLUDEDIR & BOOST_LIBRARYDIR are different

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, ie:

- 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?

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM