Cmake unable to find Boost

一笑奈何 提交于 2019-12-25 18:36:52

问题


I tried to make PCL example project.here i used cmake to build. But cmake gives an Error as below

Could NOT find Boost
CMake Error at C:/Program Files/PCL 1.5.1/cmake/PCLConfig.cmake:38 (message):
  common is required but boost was not found
Call Stack (most recent call first):
  C:/Program Files/PCL 1.5.1/cmake/PCLConfig.cmake:346 (pcl_report_not_found)
  C:/Program Files/PCL 1.5.1/cmake/PCLConfig.cmake:491 (find_external_library)
  CMakeLists.txt:5 (find_package)

I have Boost in C:\Program Files\PCL 1.5.1\3rdParty\Boost , since cmake couldn't find in default location i think it might throw an error. To get rid of that error i add

SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "C:/Program Files/PCL 1.5.1/3rdParty/Boost/include")
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "C:/Program Files/PCL 1.5.1/3rdParty/Boost/lib")

before the macro(find_boost) But also throw the same Error. please find my PCLConfig.cmake below (i have mentioned the code snippet that relates to boost)

SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "C:/Program Files/PCL 1.5.1/3rdParty/Boost/include")
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "C:/Program Files/PCL 1.5.1/3rdParty/Boost/lib")
    macro(find_boost)
      if(PCL_ALL_IN_ONE_INSTALLER)
        set(BOOST_ROOT "${PCL_ROOT}/3rdParty/Boost")
      elseif(NOT BOOST_INCLUDEDIR)
        set(BOOST_INCLUDEDIR "d:/git/SuperBuild/build/CMakeExternal/Install/Boost/include")
      endif(PCL_ALL_IN_ONE_INSTALLER)
      # use static Boost in Windows
      if(WIN32)
        set(Boost_USE_STATIC_LIBS ON)
        set(Boost_USE_STATIC ON)
      endif(WIN32)
      if(${CMAKE_VERSION} VERSION_LESS 2.8.5)
        SET(Boost_ADDITIONAL_VERSIONS "1.43" "1.43.0" "1.44" "1.44.0" "1.45" "1.45.0" "1.46.1" "1.46.0" "1.46" "1.47" "1.47.0")
      else(${CMAKE_VERSION} VERSION_LESS 2.8.5)
        SET(Boost_ADDITIONAL_VERSIONS "1.47" "1.47.0")
      endif(${CMAKE_VERSION} VERSION_LESS 2.8.5)
      # Disable the config mode of find_package(Boost)
      set(Boost_NO_BOOST_CMAKE ON)
      find_package(Boost 1.40.0 ${QUIET_} COMPONENTS system filesystem thread date_time iostreams)
      set(BOOST_FOUND ${Boost_FOUND})
      set(BOOST_INCLUDE_DIRS "${Boost_INCLUDE_DIR}")
      set(BOOST_LIBRARY_DIRS "${Boost_LIBRARY_DIRS}")
      set(BOOST_LIBRARIES ${Boost_LIBRARIES})
      if(WIN32)
        set(BOOST_DEFINITIONS ${BOOST_DEFINITIONS} -DBOOST_ALL_NO_LIB)
      endif(WIN32)
    endmacro(find_boost)

Any help is appreciated to this matter.


回答1:


try setting the boost vars directly as following :

    macro(find_boost)
  if(PCL_ALL_IN_ONE_INSTALLER)
    set(BOOST_ROOT "${PCL_ROOT}/3rdParty/Boost")
  elseif(NOT BOOST_INCLUDEDIR)
        set(BOOST_INCLUDEDIR ""C:/Program Files/PCL 1.5.1/3rdParty/Boost/include")
        set(BOOST_INCLUDEDIR ""C:/Program Files/PCL 1.5.1/3rdParty/Boost/include")
        set(Boost_LIBRARY_DIR "C:/Program Files/PCL 1.5.1/3rdParty/Boost/lib")
  endif(PCL_ALL_IN_ONE_INSTALLER)
  # use static Boost in Windows
  if(WIN32)
    set(Boost_USE_STATIC_LIBS ON)
    set(Boost_USE_STATIC ON)
  endif(WIN32)
  if(${CMAKE_VERSION} VERSION_LESS 2.8.5)
    SET(Boost_ADDITIONAL_VERSIONS "1.43" "1.43.0" "1.44" "1.44.0" "1.45" "1.45.0" "1.46.1" "1.46.0" "1.46" "1.47" "1.47.0")
  else(${CMAKE_VERSION} VERSION_LESS 2.8.5)
    SET(Boost_ADDITIONAL_VERSIONS "1.47" "1.47.0")
  endif(${CMAKE_VERSION} VERSION_LESS 2.8.5)
  # Disable the config mode of find_package(Boost)
  set(Boost_NO_BOOST_CMAKE ON)
  find_package(Boost 1.40.0 ${QUIET_} COMPONENTS system filesystem thread date_time iostreams)
  set(BOOST_FOUND ${Boost_FOUND})
  set(BOOST_INCLUDE_DIRS "${Boost_INCLUDE_DIR}")
  set(BOOST_LIBRARY_DIRS "${Boost_LIBRARY_DIRS}")
  set(BOOST_LIBRARIES ${Boost_LIBRARIES})
  if(WIN32)
    set(BOOST_DEFINITIONS ${BOOST_DEFINITIONS} -DBOOST_ALL_NO_LIB)
  endif(WIN32)
endmacro(find_boost)



回答2:


Use the graphical tool in CMake. (Hardcoding paths directly will work, but it's not what you want to do, it defeats the purpose of CMake).

Various variables will appear like BOOST_ROOT, BOOST_DIR and so on. In the graphical tool, click and then point the variable to the Boost directories. Depending on exactly how the CMake file has been set up you might have to play with it for a while until it is happy, but eventually it should find Boost. You must have installed Boost correctly, including compiling the non-jeader components, but I assume that has been checked already.



来源:https://stackoverflow.com/questions/42050193/cmake-unable-to-find-boost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!