【问题标题】:CMake found Boost but Make cannot find include file [duplicate]CMake找到了Boost但Make找不到包含文件[重复]
【发布时间】:2017-05-17 08:37:09
【问题描述】:

我目前遇到 Boost 问题。在 CMake 阶段,它明确表示找到了 boost:

-- Boost version: 1.61.0
-- Found the following Boost libraries:
--   filesystem
--   program_options
--   iostreams
--   timer
--   system
--   regex

但是在make阶段从生成的Makefile:

Timer.h(26): catastrophic error: cannot open source file "boost/timer/timer.hpp"
  #include <boost/timer/timer.hpp>
[..]                                  ^

Function.h(29): catastrophic error: cannot open source file "boost/ptr_container/ptr_map.hpp"
  #include <boost/ptr_container/ptr_map.hpp>
[..]

基本上,Makefile 似乎没有找到任何boost 的标头。我什至已经声明Boost_INCLUDEDIRBoost_LIBRARYDIR - 区分大小写。看起来没有帮助。

可能的原因是什么?编译器之间是否存在一些冲突,即gcc/icccmake 生成器? (纯属猜测——我不是这方面的专家……)

编辑:这是在CMakeLists.txt文件中找到boost的过程:http://pastebin.com/7m3yAYk5FindBOOST.cmake在这里:https://github.com/Kitware/CMake/blob/master/Modules/FindBoost.cmake

【问题讨论】:

  • 请编辑您的问题并添加您的 CMakeLists.txt 寻找 Boost 的内容。在不知道您如何搜索和使用 Boost 的情况下无法回答您的问题
  • 你有这个include_directories(SYSTEM ${Boost_INCLUDE_DIR})

标签: c++ boost makefile cmake


【解决方案1】:

找到一个库并包含它是两件不同的事情。

您不仅需要找到 Boost,还需要包含它的标头并链接到它的库。一个简单的 CMakeLists.txt 示例:

FIND_PACKAGE( Boost 1.61 COMPONENTS filesystem program_options iostreams timer REQUIRED )
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )

ADD_EXECUTABLE( myProgram myMain.cpp )

TARGET_LINK_LIBRARIES( myProgram ${Boost_LIBRARIES} )

如果您已经这样做了,请更新您的问题以包含该信息。

【讨论】:

  • 这不适用于我在 Windows 上使用 find_package(Boost 1.70.0 REQUIRED COMPONENTS graph) 在 Cmake 3.17 上。仍然无法打开源文件...有什么想法吗?
猜你喜欢
  • 2013-03-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-20
相关资源
最近更新 更多