如何让 CMake 找到我的替代 Boost 安装?

发布于 2024-09-05 07:32:09 字数 361 浏览 5 评论 0原文

我已在 /usr/local 中安装了最新版本的 Boost(包含在 /usr/local/include/boost 中,库在 /usr/local 中/lib/boost),我现在尝试从源代码安装 Wt,但 CMake(版本 2.6)似乎找不到 Boost 安装。它试图提供有关设置 BOOST_DIR 和 Boost_LIBRARYDIR 的有用建议,但我无法通过调整这些变量来使其工作。

我收到的最新错误消息是它找不到库,但似乎表明它正在使用“/usr/local/include”作为包含路径,这是不正确的(我可以'似乎修复它)。他们是否有解决方案,或者我是否需要在 CMake 内部进行修改才能弄清楚?

I have installed the most recent version of Boost in /usr/local (with includes in /usr/local/include/boost and libraries in /usr/local/lib/boost) and I am now attempting to install Wt from source, but CMake (version 2.6) can't seem to find the Boost installation. It tries to give helpful suggestions about setting BOOST_DIR and Boost_LIBRARYDIR, but I haven't been able to get it to work by tweaking these variables.

The most recent error message that I get is that it can't find the libraries, but it seems to indicate that it is using "/usr/local/include" for the include path, which isn't correct (and I can't seem to fix it). Is there a solution for this off the top of their head, or do I need to go mucking around inside CMake to figure it out?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(16

感性 2024-09-12 07:32:09

您应该查看 FindBoost.cmake 脚本,它处理 Boost 检测并设置所有 Boost 变量。它通常驻留在 /usr/share/cmake-2.6/Modules/ 中。您将在其中找到文档。例如:

# These last three variables are available also as environment variables:
#
#   BOOST_ROOT or BOOSTROOT      The preferred installation prefix for searching for
#                                Boost.  Set this if the module has problems finding
#                                the proper Boost installation.
#

与 BOOST_ROOT 相比,您引用的变量实际上是由 FindBoost 模块设置的变量。请注意,您不必(并且可能也不想)编辑 CMake 项目配置来设置 BOOST_ROOT。相反,您应该使用环境变量,例如调用

# BOOST_ROOT=/usr/local/... ccmake 。

You should have a look at FindBoost.cmake script, which handles Boost detection and setting up all Boost variables. It typically resides in /usr/share/cmake-2.6/Modules/. In it, you will find documentation. For instance:

# These last three variables are available also as environment variables:
#
#   BOOST_ROOT or BOOSTROOT      The preferred installation prefix for searching for
#                                Boost.  Set this if the module has problems finding
#                                the proper Boost installation.
#

In contrast to BOOST_ROOT, the variables you are referring to are actually variables that are set by the FindBoost module. Note that you don't have to (and probably also don't want to) edit your CMake project configuration to set BOOST_ROOT. Instead, you should use the environment variable, e.g. calling

# BOOST_ROOT=/usr/local/... ccmake .

最偏执的依靠 2024-09-12 07:32:09

我终于能够得到我想要的东西

cmake -DCMAKE_INSTALL_PREFIX=$TARGET \
    -DBoost_NO_BOOST_CMAKE=TRUE \
    -DBoost_NO_SYSTEM_PATHS=TRUE \
    -DBOOST_ROOT:PATHNAME=$TARGET \
    -DBoost_LIBRARY_DIRS:FILEPATH=${TARGET}/lib

I was finally able to get what I wanted with

cmake -DCMAKE_INSTALL_PREFIX=$TARGET \
    -DBoost_NO_BOOST_CMAKE=TRUE \
    -DBoost_NO_SYSTEM_PATHS=TRUE \
    -DBOOST_ROOT:PATHNAME=$TARGET \
    -DBoost_LIBRARY_DIRS:FILEPATH=${TARGET}/lib
不交电费瞎发啥光 2024-09-12 07:32:09

简短版本

您只需要 BOOST_ROOT,但如果您有多个安装或针对 iOS 或 Android 的交叉编译,您将需要禁用在系统中搜索本地 Boost。在这种情况下,add Boost_NO_SYSTEM_PATHS 设置为 false。

set( BOOST_ROOT "" CACHE PATH "Boost library path" )
set( Boost_NO_SYSTEM_PATHS on CACHE BOOL "Do not search system for Boost" )

通常,这是使用语法 -D=value 在 CMake 命令行上传递的。

较长的版本

正式来说 FindBoost 页面指出这些变量应该是用于“暗示”Boost的位置。

该模块从变量中读取有关搜索位置的提示:

BOOST_ROOT             - Preferred installation prefix
 (or BOOSTROOT)
BOOST_INCLUDEDIR       - Preferred include directory e.g. <prefix>/include
BOOST_LIBRARYDIR       - Preferred library directory e.g. <prefix>/lib
Boost_NO_SYSTEM_PATHS  - Set to ON to disable searching in locations not
                         specified by these hint variables. Default is OFF.
Boost_ADDITIONAL_VERSIONS
                       - List of Boost versions not known to this module
                         (Boost install locations may contain the version)

这在理论上是正确的咒语:

cmake -DBoost_NO_SYSTEM_PATHS=TRUE \
      -DBOOST_ROOT=/path/to/boost-dir

当您从源代码编译时

include( ExternalProject )

set( boost_URL "http://sourceforge.net/projects/boost/files/boost/1.63.0/boost_1_63_0.tar.bz2" )
set( boost_SHA1 "9f1dd4fa364a3e3156a77dc17aa562ef06404ff6" )
set( boost_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/third_party/boost )
set( boost_INCLUDE_DIR ${boost_INSTALL}/include )
set( boost_LIB_DIR ${boost_INSTALL}/lib )

ExternalProject_Add( boost
        PREFIX boost
        URL ${boost_URL}
        URL_HASH SHA1=${boost_SHA1}
        BUILD_IN_SOURCE 1
        CONFIGURE_COMMAND
        ./bootstrap.sh
        --with-libraries=filesystem
        --with-libraries=system
        --with-libraries=date_time
        --prefix=<INSTALL_DIR>
        BUILD_COMMAND
        ./b2 install link=static variant=release threading=multi runtime-link=static
        INSTALL_COMMAND ""
        INSTALL_DIR ${boost_INSTALL} )

set( Boost_LIBRARIES
        ${boost_LIB_DIR}/libboost_filesystem.a
        ${boost_LIB_DIR}/libboost_system.a
        ${boost_LIB_DIR}/libboost_date_time.a )
message( STATUS "Boost static libs: " ${Boost_LIBRARIES} )

然后,当您调用此脚本时,您需要包含 boost.cmake 脚本(我的脚本位于 a 子目录中),包含标头,指示依赖性并链接库。

include( boost )
include_directories( ${boost_INCLUDE_DIR} )
add_dependencies( MyProject boost )
target_link_libraries( MyProject
                       ${Boost_LIBRARIES} )

The short version

You only need BOOST_ROOT, but you're going to want to disable searching the system for your local Boost if you have multiple installations or cross-compiling for iOS or Android. In which case add Boost_NO_SYSTEM_PATHS is set to false.

set( BOOST_ROOT "" CACHE PATH "Boost library path" )
set( Boost_NO_SYSTEM_PATHS on CACHE BOOL "Do not search system for Boost" )

Normally this is passed on the CMake command-line using the syntax -D<VAR>=value.

The longer version

Officially speaking the FindBoost page states these variables should be used to 'hint' the location of Boost.

This module reads hints about search locations from variables:

BOOST_ROOT             - Preferred installation prefix
 (or BOOSTROOT)
BOOST_INCLUDEDIR       - Preferred include directory e.g. <prefix>/include
BOOST_LIBRARYDIR       - Preferred library directory e.g. <prefix>/lib
Boost_NO_SYSTEM_PATHS  - Set to ON to disable searching in locations not
                         specified by these hint variables. Default is OFF.
Boost_ADDITIONAL_VERSIONS
                       - List of Boost versions not known to this module
                         (Boost install locations may contain the version)

This makes a theoretically correct incantation:

cmake -DBoost_NO_SYSTEM_PATHS=TRUE \
      -DBOOST_ROOT=/path/to/boost-dir

When you compile from source

include( ExternalProject )

set( boost_URL "http://sourceforge.net/projects/boost/files/boost/1.63.0/boost_1_63_0.tar.bz2" )
set( boost_SHA1 "9f1dd4fa364a3e3156a77dc17aa562ef06404ff6" )
set( boost_INSTALL ${CMAKE_CURRENT_BINARY_DIR}/third_party/boost )
set( boost_INCLUDE_DIR ${boost_INSTALL}/include )
set( boost_LIB_DIR ${boost_INSTALL}/lib )

ExternalProject_Add( boost
        PREFIX boost
        URL ${boost_URL}
        URL_HASH SHA1=${boost_SHA1}
        BUILD_IN_SOURCE 1
        CONFIGURE_COMMAND
        ./bootstrap.sh
        --with-libraries=filesystem
        --with-libraries=system
        --with-libraries=date_time
        --prefix=<INSTALL_DIR>
        BUILD_COMMAND
        ./b2 install link=static variant=release threading=multi runtime-link=static
        INSTALL_COMMAND ""
        INSTALL_DIR ${boost_INSTALL} )

set( Boost_LIBRARIES
        ${boost_LIB_DIR}/libboost_filesystem.a
        ${boost_LIB_DIR}/libboost_system.a
        ${boost_LIB_DIR}/libboost_date_time.a )
message( STATUS "Boost static libs: " ${Boost_LIBRARIES} )

Then when you call this script you'll need to include the boost.cmake script (mine is in the a subdirectory), include the headers, indicate the dependency, and link the libraries.

include( boost )
include_directories( ${boost_INCLUDE_DIR} )
add_dependencies( MyProject boost )
target_link_libraries( MyProject
                       ${Boost_LIBRARIES} )
早乙女 2024-09-12 07:32:09

我遇到了类似的问题,CMake 仅找到供应商安装的 Boost,但我的集群有一个本地安装的版本,这正是我希望它使用的版本。 Red Hat Linux 6。

无论如何,看起来所有的 BOOSTROOTBOOST_ROOTBoost_DIR 内容都会让人烦恼,除非也设置 Boost_NO_BOOST_CMAKE(例如添加到命令行-DBoost_NO_BOOST_CMAKE=TRUE)。

(我承认 CMake 对于多平台很有用,但我仍然讨厌它。)

I had a similar issue, CMake finding a vendor-installed Boost only, but my cluster had a locally installed version which is what I wanted it to use. Red Hat Linux 6.

Anyway, it looks like all the BOOSTROOT, BOOST_ROOT, and Boost_DIR stuff would get annoyed unless one also sets Boost_NO_BOOST_CMAKE (e.g add to cmd line -DBoost_NO_BOOST_CMAKE=TRUE).

(I will concede the usefulness of CMake for multiplatform, but I can still hate it.)

音盲 2024-09-12 07:32:09

一般来说,最常见的错误是添加新选项后不清理构建目录。我从系统数据包管理器安装了 Boost。它的版本是1.49。

我还下载了 Boost 1.53 并将其“安装”在 $HOME/installs 下。

我在项目中唯一要做的就是(我将源代码保存在 my_project_directory/src 中):

cd my_project_directory
mkdir build
cd build
cmake -DCMAKE_INCLUDE_PATH=$HOME/installs/include -DCMAKE_LIBRARY_PATH=$HOME/installs/lib ../src

就是这样。太棒了。

但如果我在 cd build 之后进行 -> cmake ../src 它将从系统路径设置Boost。然后执行 cmake -DCMAKE_INCLUDE_PATH=$HOME/installs/include -DCMAKE_LIBRARY_PATH=$HOME/installs/lib ../src 不会改变任何内容。

您必须清理构建目录cd build && rm -rf * ;))

Generally the most common mistake is not cleaning your build directory after adding new options. I have Boost installed from system packet manager. Its version is 1.49.

I also downloaded Boost 1.53 and "installed" it under $HOME/installs.

The only thing that I had to do in my project was to (I keep sources in my_project_directory/src):

cd my_project_directory
mkdir build
cd build
cmake -DCMAKE_INCLUDE_PATH=$HOME/installs/include -DCMAKE_LIBRARY_PATH=$HOME/installs/lib ../src

And that's it. Ta bum tss.

But if I'd make after cd build -> cmake ../src it would set Boost from the system path. Then doing cmake -DCMAKE_INCLUDE_PATH=$HOME/installs/include -DCMAKE_LIBRARY_PATH=$HOME/installs/lib ../src would change nothing.

You have to clean your build directory ( cd build && rm -rf * ;) )

怕倦 2024-09-12 07:32:09

我遇到了类似的问题,我可以通过将以下行添加到我的 CMakeLists.txt 文件中来使用自定义的 Boost 库:

set(Boost_NO_SYSTEM_PATHS TRUE)
if (Boost_NO_SYSTEM_PATHS)
  set(BOOST_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../../3p/boost")
  set(BOOST_INCLUDE_DIRS "${BOOST_ROOT}/include")
  set(BOOST_LIBRARY_DIRS "${BOOST_ROOT}/lib")
endif (Boost_NO_SYSTEM_PATHS)
find_package(Boost REQUIRED regex date_time system filesystem thread graph program_options)
include_directories(${BOOST_INCLUDE_DIRS})

I had a similar issue, and I could use customized Boost libraries by adding the below lines to my CMakeLists.txt file:

set(Boost_NO_SYSTEM_PATHS TRUE)
if (Boost_NO_SYSTEM_PATHS)
  set(BOOST_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../../3p/boost")
  set(BOOST_INCLUDE_DIRS "${BOOST_ROOT}/include")
  set(BOOST_LIBRARY_DIRS "${BOOST_ROOT}/lib")
endif (Boost_NO_SYSTEM_PATHS)
find_package(Boost REQUIRED regex date_time system filesystem thread graph program_options)
include_directories(${BOOST_INCLUDE_DIRS})
静待花开 2024-09-12 07:32:09

有一种通用方法可以为 CMake 提供有关在何处查找库的指示。

查找库时,CMake 首先在以下变量中查找:

  • CMAKE_LIBRARY_PATHLD_LIBRARY_PATH 来查找库
  • CMAKE_INCLUDE_PATHINCLUDE_PATH如果

您在其中一个环境变量中声明您的 Boost 文件,CMake 会找到它。示例:

export CMAKE_LIBRARY_PATH="/stuff/lib.boost.1.52/lib:$CMAKE_LIBRARY_PATH"
export CMAKE_INCLUDE_PATH="/stuff/lib.boost.1.52/include:$CMAKE_INCLUDE_PATH"

如果太麻烦,您还可以使用我编写的一个不错的安装工具,它将为您完成所有操作:C++ 版本经理

There is a generic method to give CMake directions about where to find libraries.

When looking for a library, CMake looks first in the following variables:

  • CMAKE_LIBRARY_PATH and LD_LIBRARY_PATH for libraries
  • CMAKE_INCLUDE_PATH and INCLUDE_PATH for includes

If you declare your Boost files in one of the environment variables, CMake will find it. Example:

export CMAKE_LIBRARY_PATH="/stuff/lib.boost.1.52/lib:$CMAKE_LIBRARY_PATH"
export CMAKE_INCLUDE_PATH="/stuff/lib.boost.1.52/include:$CMAKE_INCLUDE_PATH"

If it's too cumbersome, you can also use a nice installing tool I wrote that will do everything for you: C++ version manager

私藏温柔 2024-09-12 07:32:09

在深入研究 CMake 并进行实验后,我确定 CMake 对我的所有 Boost 库都包含在 /usr/local/lib/boost 而不是 /usr/local 中这一事实感到不满意/lib.一旦我将它们软链接回来,构建就开始工作了。

After digging around in CMake and experimenting, I determined that CMake was unhappy with the fact that all of my Boost libraries were contained in /usr/local/lib/boost and not /usr/local/lib. Once I soft-linked them back out, the build worked.

月下凄凉 2024-09-12 07:32:09

试试这个标志:-DBoost_NO_BOOST_CMAKE=TRUE。经过几个小时的尝试和修复,只有添加这个标志对我有用。

我跑的是:

mkdir build && cd build
cmake .. -DBoost_NO_BOOST_CMAKE=TRUE

Try this flag: -DBoost_NO_BOOST_CMAKE=TRUE. After hours of trying and fixing, only adding this flag worked for me.

What I ran was:

mkdir build && cd build
cmake .. -DBoost_NO_BOOST_CMAKE=TRUE
咆哮 2024-09-12 07:32:09

我花了大部分时间试图让这个工作正常进行。我尝试了所有的 -DBOOST_* &c。使用 CMake 的指令,但它一直链接到我的系统 Boost 库,即使在反复清除和重新配置我的构建区域之后也是如此。

最后,我修改了生成的 Makefile 并将 cmake_check_build_system 目标作废,不执行任何操作(如“echo ""”),这样当我运行 make 时它不会覆盖我的更改,然后执行“grep -rl "lboost_python" * | xargs sed -i "s:-lboost_python:-L/opt/sw/gcc5/usr/lib/ -lboost_python:g' 在我的 build/ 目录中显式地将所有构建命令指向我想要使用的 Boost 安装。最后,

我承认这是一个丑陋的拼凑,但我只是为了那些遇到同样的砖墙并且只想解决它的人的利益。完成工作。

I spent most of my evening trying to get this working. I tried all of the -DBOOST_* &c. directives with CMake, but it kept linking to my system Boost libraries, even after clearing and re-configuring my build area repeatedly.

At the end I modified the generated Makefile and voided the cmake_check_build_system target to do nothing (like 'echo ""') so that it wouldn't overwrite my changes when I ran make, and then did 'grep -rl "lboost_python" * | xargs sed -i "s:-lboost_python:-L/opt/sw/gcc5/usr/lib/ -lboost_python:g' in my build/ directory to explicitly point all the build commands to the Boost installation I wanted to use. Finally, that worked.

I acknowledge that it is an ugly kludge, but I am just putting it out here for the benefit of those who come up against the same brick wall, and just want to work around it and get work done.

南七夏 2024-09-12 07:32:09

在 CMake 中,您可以将以下内容添加到您的 CMakelists 中:

# install boost by apt-get method
include_directories(BEFORE SYSTEM "/usr/include") 

#  or install by building from src
# include_directories(BEFORE SYSTEM "/usr/local/include") 

此方法节省了我几个月的时间。你可以尝试一下。
顺便说一句,作为临时解决方案,您可以重命名您不希望找到的目录,如下所示:

sudo mv /usr/local/include/boost /usr/local/include/boost_bak

希望它能帮助像我一样陷入困境的人。

In CMake, you can add the following to your CMakelists:

# install boost by apt-get method
include_directories(BEFORE SYSTEM "/usr/include") 

#  or install by building from src
# include_directories(BEFORE SYSTEM "/usr/local/include") 

This method saved my serveral months. you can try it.
By the way, as a temporary solution, you can rename directories you don't expect to find as below:

sudo mv /usr/local/include/boost /usr/local/include/boost_bak

Hopefully, it will help people who are in deep trouble like me.

五里雾 2024-09-12 07:32:09

我在安装了两个版本的 Boost 的 Linux 服务器上遇到了类似的问题。一个是预编译的1.53.0版本,算作2018年的老版本;它位于 /usr/include/usr/lib64 中。我想要使​​用的版本是 1.67.0,因为我正在安装的另一个 C++ 库需要的最低版本为 1.65.1;它位于 /opt/boost 中,其中包含 includelib 子目录。正如之前答案中所建议的,我在 CMakeLists.txt 中设置变量来指定在何处查找 Boost 1.67.0,如下所示,

include_directories(/opt/boost/include/)
include_directories(/opt/boost/lib/)
set(BOOST_ROOT /opt/boost/)
set(BOOST_INCLUDEDIR /opt/boost/include/)
set(BOOST_LIBRARYDIR /opt/boost/lib)
set(Boost_NO_SYSTEM_PATHS TRUE)
set(Boost_NO_BOOST_CMAKE TRUE)

但 CMake 不接受这些更改。然后我在网上找到了一篇文章: CMake 可以使用local Boost,并意识到我需要更改CMakeCache.txt中的变量。在那里我发现与 Boost 相关的变量仍然指向默认的 Boost 1.53.0,所以难怪 CMake 不尊重我在 CMakeLists.txt 中的更改。然后我在 CMakeCache.txt 中设置了与 Boost 相关的变量,

Boost_DIR:PATH=Boost_DIR-NOTFOUND
Boost_INCLUDE_DIR:PATH=/opt/boost/include/
Boost_LIBRARY_DIR_DEBUG:PATH=/opt/boost/lib
Boost_LIBRARY_DIR_RELEASE:PATH=/opt/boost/lib

我还更改了指向 Boost 库的非标头、已编译部分的变量,以指向我想要的版本。然后CMake成功构建了依赖最新版本Boost的库。

I ran into a similar problem on a Linux server, where two versions of Boost have been installed. One is the precompiled 1.53.0 version which counts as old in 2018; it's in /usr/include and /usr/lib64. The version I want to use is 1.67.0, as a minimum version of 1.65.1 is required for another C++ library I'm installing; it's in /opt/boost, which has include and lib subdirectories. As suggested in previous answers, I set variables in CMakeLists.txt to specify where to look for Boost 1.67.0 as follows

include_directories(/opt/boost/include/)
include_directories(/opt/boost/lib/)
set(BOOST_ROOT /opt/boost/)
set(BOOST_INCLUDEDIR /opt/boost/include/)
set(BOOST_LIBRARYDIR /opt/boost/lib)
set(Boost_NO_SYSTEM_PATHS TRUE)
set(Boost_NO_BOOST_CMAKE TRUE)

But CMake doesn't honor those changes. Then I found an article online: CMake can use a local Boost, and realized that I need to change the variables in CMakeCache.txt. There I found that the Boost-related variables are still pointing to the default Boost 1.53.0, so no wonder CMake doesn't honor my changes in CMakeLists.txt. Then I set the Boost-related variables in CMakeCache.txt

Boost_DIR:PATH=Boost_DIR-NOTFOUND
Boost_INCLUDE_DIR:PATH=/opt/boost/include/
Boost_LIBRARY_DIR_DEBUG:PATH=/opt/boost/lib
Boost_LIBRARY_DIR_RELEASE:PATH=/opt/boost/lib

I also changed the variables pointing to the non-header, compiled parts of the Boost library to point to the version I want. Then CMake successfully built the library that depends on a recent version of Boost.

不回头走下去 2024-09-12 07:32:09

我也遇到了同样的问题,但不幸的是,尝试这里的提示并没有帮助。

唯一有帮助的是从 Boost 页面下载最新版本,编译并安装它
在 Ubuntu 上安装 Boost 1.50 中描述12.10

就我而言,我使用的是 Boost 1.53。

I also encountered the same problem, but trying the hints here didn't help, unfortunately.

The only thing that helped was to download the newest version from the Boost page, compile and install it as
described in Installing Boost 1.50 on Ubuntu 12.10.

In my case I worked with Boost 1.53.

芯好空 2024-09-12 07:32:09

虽然 configure 可以找到我的 Boost 安装,但 CMake 却找不到。

找到 FindBoost.cmake 并查找 LIBRARY_HINTS 以查看它正在查找哪些子包。就我而言,它需要 MPI 和图形库。

 # Compute component-specific hints.
  set(_Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT "")
  if(${COMPONENT} STREQUAL "mpi" OR ${COMPONENT} STREQUAL "mpi_python" OR
     ${COMPONENT} STREQUAL "graph_parallel")
    foreach(lib ${MPI_CXX_LIBRARIES} ${MPI_C_LIBRARIES})
      if(IS_ABSOLUTE "${lib}")
        get_filename_component(libdir "${lib}" PATH)
        string(REPLACE "\\" "/" libdir "${libdir}")
        list(APPEND _Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT ${libdir})
      endif()
    endforeach()
  endif()

apt-cache search ...我在构建代码时安装了开发包,并且开发包拖入了所有依赖项。我不太确定标准的 Boost 安装是否需要 Open MPI,但目前还可以。

sudo apt-get install libboost-mpi-dev libboost-mpi-python-dev
sudo apt-get install libboost-graph-parallel-dev

While configure could find my Boost installation, CMake could not.

Locate FindBoost.cmake and look for LIBRARY_HINTS to see what sub-packages it is looking for. In my case it wanted the MPI and graph libraries.

 # Compute component-specific hints.
  set(_Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT "")
  if(${COMPONENT} STREQUAL "mpi" OR ${COMPONENT} STREQUAL "mpi_python" OR
     ${COMPONENT} STREQUAL "graph_parallel")
    foreach(lib ${MPI_CXX_LIBRARIES} ${MPI_C_LIBRARIES})
      if(IS_ABSOLUTE "${lib}")
        get_filename_component(libdir "${lib}" PATH)
        string(REPLACE "\\" "/" libdir "${libdir}")
        list(APPEND _Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT ${libdir})
      endif()
    endforeach()
  endif()

apt-cache search ... I installed the dev packages since I was building code, and the dev package drags in all the dependencies. I'm not so sure that a standard Boost install needs Open MPI, but this is OK for now.

sudo apt-get install libboost-mpi-dev libboost-mpi-python-dev
sudo apt-get install libboost-graph-parallel-dev
单身狗的梦 2024-09-12 07:32:09

我刚刚添加了环境变量 Boost_INCLUDE_DIR 或将其添加到 cmake 命令 -DBoost_INCLUDE_DIR 并指向包含文件夹。

I just added the environment variable Boost_INCLUDE_DIR or add it to the cmake command -DBoost_INCLUDE_DIR and point to the include folder.

烟燃烟灭 2024-09-12 07:32:09

我也有同样的问题。
我的方法是通过环境变量定义要使用的版本(如果有):

# Use speficic version if BOOST_VER environment variable is defined
if(NOT "$ENV{BOOST_VER}" STREQUAL "")
    find_package (Boost "$ENV{BOOST_VER}" EXACT COMPONENTS system unit_test_framework log log_setup filesystem thread REQUIRED)
else()
    # Use default version
    find_package (Boost COMPONENTS system unit_test_framework log log_setup filesystem thread REQUIRED)
endif()

I had the same problem.
My approach was to define which version to use (if any) via an environment variable:

# Use speficic version if BOOST_VER environment variable is defined
if(NOT "$ENV{BOOST_VER}" STREQUAL "")
    find_package (Boost "$ENV{BOOST_VER}" EXACT COMPONENTS system unit_test_framework log log_setup filesystem thread REQUIRED)
else()
    # Use default version
    find_package (Boost COMPONENTS system unit_test_framework log log_setup filesystem thread REQUIRED)
endif()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文