【问题标题】:boost program_options not found未找到提升程序选项
【发布时间】:2018-01-20 21:48:46
【问题描述】:

cmake - 3.8

我在/usr/local/lib/下编译安装了boost库,但是无法通过find_package(Boost REQUIRED program_options)命令让cmake检测boost program_options。找到所有其他库find_package(Boost REQUIRED thread system),并且仅添加 program_options 会引发错误。我已经尝试了很多东西,但有点不知所措——program_options 有什么特别之处。

-- Boost version: 1.63.0
-- Found the following Boost libraries:
--   filesystem
--   regex
--   serialization
--   unit_test_framework
--   iostreams
--   thread
--   system
--   chrono
--   date_time
--   atomic

boost make 成功并构建了 program_options 库(我可以在 /usr/local/lib/ 文件夹中看到它以及其他 boost 库)。我就是不明白,为什么nt cmake会找到呢?

Error : 
  Unable to find the requested Boost libraries.

  Boost version: 1.63.0

  Boost include path: /usr/local/include

  Could not find the following Boost libraries:

          boost_program_options

  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.

目录结构

-rw-r--r-- 1 root root 1558464 Aug 12 15:46 /usr/local/lib/libboost_program_options.a
lrwxrwxrwx 1 root root      34 Aug 12 15:46 /usr/local/lib/libboost_program_options.so -> libboost_program_options.so.1.63.0*
-rwxr-xr-x 1 root root  658920 Aug 12 15:46 /usr/local/lib/libboost_program_options.so.1.63.0*

【问题讨论】:

  • 发布错误?
  • 您的 CMake 是否足够新? stackoverflow.com/a/42124857/2799037
  • @utopia 更新了帖子.. 还发布了 /usr/local/lib 的目录结构。我真的对整个错误感到困惑。

标签: boost cmake


【解决方案1】:

通过将set(Boost_DEBUG ON) set(Boost_USE_STATIC_LIBS ON) 添加到我的CMakeLists.txt 文件中,我能够在Windows 上解决此问题。这允许 CMake 找到正确版本的 boost 和 program_options。

我最终的 CMakeList.txt 看起来像这样......

add_executable(test ${TEST_SRC})

set(Boost_USE_STATIC_LIBS ON)
find_package(Boost 1.30 COMPONENTS program_options REQUIRED)

if(Boost_FOUND)
    target_include_directories(test PRIVATE ${Boost_INCLUDE_DIRS})
    target_link_libraries(test ${Boost_LIBRARIES})
endif()

【讨论】:

    【解决方案2】:

    经过数小时的调试,我放弃了并找到了解决方法。也许它会帮助某人。如果 cmake 做坏事,但你确定你的库在 boost 库文件夹中 - 只需明确链接库。

    target_link_libraries(TARGET lib1 lib2 ${Boost_LIBRARIES} libboost_program_options.so)
    

    您可能需要事先添加link_directories(/usr/local/lib/),以防 rpath 不包含 /usr/local/lib。

    【讨论】:

    • 投反对票并运行。我认为这应该被定为肇事逃逸之类的刑事犯罪。
    猜你喜欢
    • 1970-01-01
    • 2012-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-13
    • 2018-08-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多