简体   繁体   English

BOOST_INCLUDEDIR和BOOST_LIBRARYDIR不同时的find_package(Boost)错误

[英]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. 我正在尝试将Boost编译为共享库,并使它们成为我的跨平台 CMake项目的依赖项。

For that, I compiled boost for win32, x64 and linux where my boost folder structure looks like: 为此,我为win32,x64和Linux编译了boost,其中boost文件夹结构如下所示:

- 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: 如果我将lib文件夹从win32内部移动到其父目录,即:

- boost_1_69_0/
  - boost/
  - stage/
    - lib

which is the default way boost's b2 build stuff, then it's all working. 这是boost的b2构建东西的默认方式,然后一切正常。 But then I can't hold different boost binaries for different platforms. 但是,我不能为不同的平台使用不同的boost二进制文件。


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 . 使用set(Boost_DEBUG ON)我发现我的Boost是在项目使用v140时使用Visual Studio v141工具集编译的,因此FindBoost在寻找boost_filesystem-vc140-mt-x64-1_69而不是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 . 我猜问题已经转移到要么找到一种方法来强制搜索v141,要么(更好)使用--layout=system并找到一种方法来迫使它始终寻找boost_filesystem Is there a way of doing that? 有办法吗?

The problem here is that CMake searches for boost libraries matching a certain naming scheme. 这里的问题是CMake搜索与某个命名方案匹配的boost库。 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. 运行b2可执行文件时,再次使用--layout=system标志再次编译boost。 This will create library files with standard names like boost_filesystem.dll and boost_filesystem.lib . 这将创建具有标准名称(例如boost_filesystem.dllboost_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): 使用以下专用于增强变体的变量为CMake提供一些有关如何命名库文件的提示(由于我没有像您这样的等效系统,因此可能是猜测,您可能必须采用):
    • Boost_ARCHITECTURE="-x32"
    • Boost_COMPILER="-vc141"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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