cmake如何在fedora工作站中找到boost静态库包?

How does cmake find package of boost static libraries in fedora workstation?

我想在 Fedora Workstation 的 cmake 中使用 boost 库。

我安装了所有依赖项:sudo dnf install git clang make cmake flex bison boost-devel llvm-devel。这一步之后,有很多/usr/lib64/libboost-*.so个文件,而没有/usr/lib/libboost-*.so个文件。

这是我的一部分 CMakeLists.txt:

set(Boost_DEBUG ON)
set(Boost_DETAILED_FAILURE_MSG ON)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_DEBUG_LIBS OFF)
set(Boost_USE_RELEASE_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost COMPONENTS program_options system filesystem REQUIRED)

错误信息如下:

-- [ /usr/share/cmake/Modules/FindBoost.cmake:1487 ] _boost_TEST_VERSIONS = "1.73.0;1.73;1.72.0;1.72;1.71.0;1.71;1.70.0;1.70;1.69.0;1.69;1.68.0;1.68;1.67.0;1.67;1.66.0;1.66;1.65.1;1.65.0;1.65;1.64.0;1.64;1.63.0;1.63;1.62.0;1.62;1.61.0;1.61;1.60.0;1.60;1.59.0;1.59;1.58.0;1.58;1.57.0;1.57;1.56.0;1.56;1.55.0;1.55;1.54.0;1.54;1.53.0;1.53;1.52.0;1.52;1.51.0;1.51;1.50.0;1.50;1.49.0;1.49;1.48.0;1.48;1.47.0;1.47;1.46.1;1.46.0;1.46;1.45.0;1.45;1.44.0;1.44;1.43.0;1.43;1.42.0;1.42;1.41.0;1.41;1.40.0;1.40;1.39.0;1.39;1.38.0;1.38;1.37.0;1.37;1.36.1;1.36.0;1.36;1.35.1;1.35.0;1.35;1.34.1;1.34.0;1.34;1.33.1;1.33.0;1.33"
-- [ /usr/share/cmake/Modules/FindBoost.cmake:1488 ] Boost_USE_MULTITHREADED = "ON"
-- [ /usr/share/cmake/Modules/FindBoost.cmake:1489 ] Boost_USE_STATIC_LIBS = "ON"
-- [ /usr/share/cmake/Modules/FindBoost.cmake:1490 ] Boost_USE_STATIC_RUNTIME = <unset>
-- [ /usr/share/cmake/Modules/FindBoost.cmake:1491 ] Boost_ADDITIONAL_VERSIONS = <unset>
-- [ /usr/share/cmake/Modules/FindBoost.cmake:1492 ] Boost_NO_SYSTEM_PATHS = <unset>
-- [ /usr/share/cmake/Modules/FindBoost.cmake:1524 ] BOOST_ROOT = <unset>
-- [ /usr/share/cmake/Modules/FindBoost.cmake:1525 ] ENV{BOOST_ROOT} = <unset>
-- [ /usr/share/cmake/Modules/FindBoost.cmake:1526 ] BOOST_INCLUDEDIR = <unset>
-- [ /usr/share/cmake/Modules/FindBoost.cmake:1527 ] ENV{BOOST_INCLUDEDIR} = <unset>
-- [ /usr/share/cmake/Modules/FindBoost.cmake:1528 ] BOOST_LIBRARYDIR = <unset>
-- [ /usr/share/cmake/Modules/FindBoost.cmake:1529 ] ENV{BOOST_LIBRARYDIR} = <unset>
-- [ /usr/share/cmake/Modules/FindBoost.cmake:1617 ] location of version.hpp: /usr/include/boost/version.hpp
-- [ /usr/share/cmake/Modules/FindBoost.cmake:1657 ] Boost_VERSION = "106900"
-- [ /usr/share/cmake/Modules/FindBoost.cmake:1658 ] Boost_VERSION_STRING = "1.69.0"
-- [ /usr/share/cmake/Modules/FindBoost.cmake:1659 ] Boost_VERSION_MACRO = "106900"
-- [ /usr/share/cmake/Modules/FindBoost.cmake:1660 ] Boost_VERSION_MAJOR = "1"
-- [ /usr/share/cmake/Modules/FindBoost.cmake:1661 ] Boost_VERSION_MINOR = "69"
-- [ /usr/share/cmake/Modules/FindBoost.cmake:1662 ] Boost_VERSION_PATCH = "0"
-- [ /usr/share/cmake/Modules/FindBoost.cmake:1663 ] Boost_VERSION_COUNT = "3"
-- [ /usr/share/cmake/Modules/FindBoost.cmake:1680 ] Boost_LIB_PREFIX = ""
-- [ /usr/share/cmake/Modules/FindBoost.cmake:1681 ] Boost_NAMESPACE = "boost"
-- [ /usr/share/cmake/Modules/FindBoost.cmake:797 ] _boost_COMPILER = "-gcc10" (guessed)
-- [ /usr/share/cmake/Modules/FindBoost.cmake:1717 ] _boost_MULTITHREADED = "-mt"
-- [ /usr/share/cmake/Modules/FindBoost.cmake:1794 ] _boost_ARCHITECTURE_TAG = "" (detected)
-- [ /usr/share/cmake/Modules/FindBoost.cmake:1798 ] _boost_RELEASE_ABI_TAG = "-"
-- [ /usr/share/cmake/Modules/FindBoost.cmake:1799 ] _boost_DEBUG_ABI_TAG = "-d"
-- [ /usr/share/cmake/Modules/FindBoost.cmake:1859 ] _boost_LIBRARY_SEARCH_DIRS_RELEASE = "/usr/include/lib;/usr/include/../lib;/usr/include/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib"
-- [ /usr/share/cmake/Modules/FindBoost.cmake:1860 ] _boost_LIBRARY_SEARCH_DIRS_DEBUG = "/usr/include/lib;/usr/include/../lib;/usr/include/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib"
-- [ /usr/share/cmake/Modules/FindBoost.cmake:2045 ] Searching for PROGRAM_OPTIONS_LIBRARY_RELEASE: boost_program_options-gcc10-mt-1_69;boost_program_options-gcc10-mt;boost_program_options-gcc10-mt;boost_program_options-mt-1_69;boost_program_options-mt;boost_program_options-mt;boost_program_options-mt;boost_program_options

-- [ /usr/share/cmake/Modules/FindBoost.cmake:2100 ] Searching for PROGRAM_OPTIONS_LIBRARY_DEBUG: boost_program_options-gcc10-mt-d-1_69;boost_program_options-gcc10-mt-d;boost_program_options-gcc10-mt-d;boost_program_options-mt-d-1_69;boost_program_options-mt-d;boost_program_options-mt-d;boost_program_options-mt;boost_program_options
-- [ /usr/share/cmake/Modules/FindBoost.cmake:2045 ] Searching for SYSTEM_LIBRARY_RELEASE: boost_system-gcc10-mt-1_69;boost_system-gcc10-mt;boost_system-gcc10-mt;boost_system-mt-1_69;boost_system-mt;boost_system-mt;boost_system-mt;boost_system
-- [ /usr/share/cmake/Modules/FindBoost.cmake:2100 ] Searching for SYSTEM_LIBRARY_DEBUG: boost_system-gcc10-mt-d-1_69;boost_system-gcc10-mt-d;boost_system-gcc10-mt-d;boost_system-mt-d-1_69;boost_system-mt-d;boost_system-mt-d;boost_system-mt;boost_system
-- [ /usr/share/cmake/Modules/FindBoost.cmake:2045 ] Searching for FILESYSTEM_LIBRARY_RELEASE: boost_filesystem-gcc10-mt-1_69;boost_filesystem-gcc10-mt;boost_filesystem-gcc10-mt;boost_filesystem-mt-1_69;boost_filesystem-mt;boost_filesystem-mt;boost_filesystem-mt;boost_filesystem
-- [ /usr/share/cmake/Modules/FindBoost.cmake:2100 ] Searching for FILESYSTEM_LIBRARY_DEBUG: boost_filesystem-gcc10-mt-d-1_69;boost_filesystem-gcc10-mt-d;boost_filesystem-gcc10-mt-d;boost_filesystem-mt-d-1_69;boost_filesystem-mt-d;boost_filesystem-mt-d;boost_filesystem-mt;boost_filesystem
CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:164 (message):
  Could NOT find Boost (missing: program_options system filesystem) (found
  version "1.69.0")
Call Stack (most recent call first):
  /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:445 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake/Modules/FindBoost.cmake:2166 (find_package_handle_standard_args)
  src/CMakeLists.txt:48 (find_package)


-- Configuring incomplete, errors occurred!
See also "/home/linrongbin/shepherd/debug/CMakeFiles/CMakeOutput.log".
See also "/home/linrongbin/shepherd/debug/CMakeFiles/CMakeError.log".
gmake: *** No targets specified and no makefile found.  Stop.

我发现我的 CMakeLists.txt 中有 2 个问题:

  1. cmake 未将 /usr/lib64 检测为 boost 库目录。我尝试在 ~/.bashrc 中使用 export BOOST_LIBRARYDIR=/usr/lib64。此问题似乎已解决。

  2. /usr/lib64里有libboost_program_options.solibboost_program_options.so.1.69.0,但是没有静态boost库文件。我想 link 静态 boost 库文件,就像 libboost_program_options.a 一样。但是我找不到任何 .a 个文件。

我应该如何配置 cmake 才能使 find_package 正常工作?

我假设您使用的是 Fedora boost 和 boost-dev 软件包,其中仅包含作为共享库的 boost 库文件。

如果您需要静态库文件,则需要按照说明构建它们 here

我通常在用户目录下构建库文件,然后使用sudo cp -a将它们复制到/usr/lib64