我想使用Point Cloud Library编译一个简单的项目。不幸的是,它使用的是旧版本的boost库,因为我目前已通过官方存储库安装。
所以我在/opt/oldlibs/boost/libs
中安装了较旧的库。我尝试在CMakeLists.txt中设置这个新路径,但不知何故cmake仍然使用/usr/lib
中安装的当前版本。我在CMakeLists.txt
文件中做错了什么?
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
cmake_policy(SET CMP0053 OLD)
project(cloud_viewer)
find_package(PCL 1.2 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
# Add old boost library
link_directories("/usr/oldlibs/libs")
set(Boost_NO_SYSTEM_PATHS TRUE)
if (Boost_NO_SYSTEM_PATHS)
set(BOOST_ROOT "/opt/oldlibs/boost")
set(BOOST_INCLUDE_DIRS "/usr/include/boost")
set(BOOST_LIBRARY_DIRS "${BOOST_ROOT}/libs")
endif (Boost_NO_SYSTEM_PATHS)
find_package(Boost REQUIRED regex date_time system filesystem thread graph program_options serialization iostreams chrono atomic)
include_directories(${BOOST_INCLUDE_DIRS})
add_executable (cloud_viewer cloud_viewer.cpp)
target_link_libraries (cloud_viewer ${PCL_LIBRARIES})
cmake的(部分)输出是:
-- Boost version: 1.64.0
-- Found the following Boost libraries:
-- regex
-- date_time
-- system
-- filesystem
-- thread
-- graph
-- program_options
-- serialization
-- iostreams
-- chrono
-- atomic
但我需要1.63。我做错了什么?我使用arch linux,我目前的cmake版本是3.8.2。
我更新了CMakeLists.txt
:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
cmake_policy(SET CMP0053 OLD)
project(cloud_viewer)
find_package(PCL 1.2 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
# Add old boost library
set(BOOST_VERSION_REQUIRED "1.63.0")
set(Boost_NO_SYSTEM_PATHS TRUE)
if (Boost_NO_SYSTEM_PATHS)
set(BOOST_ROOT "/opt/oldlibs/boost")
set(BOOST_INCLUDE_DIRS "${BOOST_ROOT}/include")
set(BOOST_LIBRARY_DIRS "${BOOST_ROOT}/lib")
endif (Boost_NO_SYSTEM_PATHS)
include_directories(${BOOST_INCLUDE_DIRS})
find_package(Boost ${BOOST_VERSION_REQUIRED} EXACT REQUIRED regex date_time system filesystem thread graph program_options serialization iostreams chrono atomic)
add_executable (cloud_viewer cloud_viewer.cpp)
target_link_libraries (cloud_viewer ${PCL_LIBRARIES})
Cmake现在明白我想使用旧版本,但仍无法找到它。我有其他错误吗?我通过从/var/cache/pacman/pkg/' and extracted it to
/ opt / oldlibs / boost /`中提取by packman缓存版本来安装旧包。
usr目录如下所示:
usr
├── oldlib
│ ├── boost
│ │ ├── bin
│ │ ├── include (contains all header files)
│ │ ├── lib (contains all libraries, static and shared)
│ │ └── share
这是cmake输出的一部分:
CMake Error at /usr/share/cmake-3.8/Modules/FindBoost.cmake:1842 (message):
Unable to find the requested Boost libraries.
Boost version: 1.64.0
Boost include path: /usr/include
Detected version of Boost is too new. Requested version was 1.63.
Call Stack (most recent call first):
CMakeLists.txt:23 (find_package)
我还尝试使用选项cmake
运行-DCMAKE_PREFIX_PATH=/opt/oldlibs/boost/lib
并改变路径。它没有改变任何东西。
答案 0 :(得分:1)
您的find_package()
似乎有误,因为您没有在其上指定版本要求:
find_package(Boost REQUIRED regex date_time system filesystem thread graph program_options serialization iostreams chrono atomic)
这要求cmake
提升Boost,理解“任何提升都很好”。您知道这个假设不成立,因此您应该指定所需的版本:
set(BOOST_VERSION_REQUIRED "your version value here") # adjust as needed
find_package(Boost ${BOOST_VERSION_REQUIRED} REQUIRED regex date_time system filesystem thread graph program_options serialization iostreams chrono atomic)
如果仍然不起作用(因为cmake
的版本控制惯例导致它更喜欢较新的Boost,假设更新更好...),那么你可以指定EXACT
到迫使版本。
set(BOOST_VERSION_REQUIRED "your version value here") # adjust as needed
find_package(Boost ${BOOST_VERSION_REQUIRED} EXACT REQUIRED regex date_time system filesystem thread graph program_options serialization iostreams chrono atomic)