即使 BOOST_LIBRARYDIR 设置正确,CMake Find Package Boost 也会失败

CMake Find Package Boost Fails Even with BOOST_LIBRARYDIR set correctly

当运行

mkdir -p build && cd build && cmake -DCMAKE_INSTALL_PREFIX=/home/install -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=On ..; cd ../

在第 3 方库中。我收到以下错误。

CMake Error at /usr/local/share/cmake-3.5/Modules/FindBoost.cmake:1657 (message):
  Unable to find the requested Boost libraries.

  Boost version: 1.67.0

  Boost include path: /usr/local/include

  Could not find the following static Boost libraries:

          boost_thread
          boost_date_time

  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.

因此根据我添加的其他几个帖子:

set(BOOST_ROOT /usr/local)
set(BOOST_LIBRARYDIR ${BOOST_ROOT}/lib)
message(STATUS "BOOST_LIBRARYDIR = ${BOOST_LIBRARYDIR}")

他们的 CMakeLists.txt。这给了我以下信息:

-- BOOST_LIBRARYDIR = /usr/local/lib
-- Using CPU native flags for SSE optimization: -march=native
-- -- GCC > 4.3 found, enabling -Wabi
-- Found OpenMP
...

但是,我仍然遇到同样的错误。列出 BOOST_LIBRARYDIR 的内容表示库在那里。

root@74fdb1dd14f4:~/code/pcl# ls /usr/local/lib
cmake                  libboost_prg_exec_monitor.so.1.67.0     libflann.so.1.9
libboost_atomic.a          libboost_program_options.a          libflann.so.1.9.1-003
libboost_atomic.so         libboost_program_options.so         libflann_cpp.so
libboost_atomic.so.1.67.0      libboost_program_options.so.1.67.0      libflann_cpp.so.1.9
libboost_chrono.a          libboost_regex.a                libflann_cpp.so.1.9.1-003
libboost_chrono.so         libboost_regex.so               libflann_cpp_s.a
libboost_chrono.so.1.67.0      libboost_regex.so.1.67.0            libflann_s.a
libboost_date_time.a           libboost_system.a               libload_qos_controller-1.0.1.so
libboost_date_time.so          libboost_system.so              libload_qos_controller.la
libboost_date_time.so.1.67.0   libboost_system.so.1.67.0           libload_qos_controller.so
libboost_filesystem.a          libboost_test_exec_monitor.a        liblogrotate_container_logger-1.0.1.so
libboost_filesystem.so         libboost_thread.a               liblogrotate_container_logger.la
libboost_filesystem.so.1.67.0  libboost_thread.so              liblogrotate_container_logger.so
libboost_graph.a           libboost_thread.so.1.67.0           libmesos-1.0.1.so
libboost_graph.so          libboost_timer.a                libmesos.la
libboost_graph.so.1.67.0       libboost_timer.so               libmesos.so
libboost_log.a             libboost_timer.so.1.67.0            mesos
libboost_log.so            libboost_unit_test_framework.a          mesos-modules
libboost_log.so.1.67.0         libboost_unit_test_framework.so         pkgconfig
libboost_log_setup.a           libboost_unit_test_framework.so.1.67.0  python2.7
libboost_log_setup.so          libfixed_resource_estimator-1.0.1.so    python3.4
libboost_log_setup.so.1.67.0   libfixed_resource_estimator.la          python3.5
libboost_prg_exec_monitor.a    libfixed_resource_estimator.so
libboost_prg_exec_monitor.so   libflann.so

为什么 CMake 找不到库?

你的 CMake 版本(我从命令行猜到的是 3.5)对于 Boost 1.67 来说太旧了。 Boost 从 1.66.0 版本开始更改了它的命名方案,因此 set(Boost_ADDITIONAL_VERSIONS 1.67 1.67.0) 将不起作用。有关详细信息,请参阅此 。升级您的 CMake 版本或降低您的 Boost 版本要求(如果可能)。