Natjo
Natjo

Reputation: 2128

Force cmake to use older boost library

I want to compile a simple project using the Point Cloud Library. Unfortunately it uses an older version of the boost library as I currently have installed via official repositories.

So I installed the older libraries in /opt/oldlibs/boost/libs. I try to set in the CMakeLists.txt this new path, but somehow cmake still uses the current version installed in /usr/lib. Did I do something wrong in my CMakeLists.txt file?

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})

The (part of the) output of cmake is:

-- Boost version: 1.64.0
-- Found the following Boost libraries:
--   regex
--   date_time
--   system
--   filesystem
--   thread
--   graph
--   program_options
--   serialization
--   iostreams
--   chrono
--   atomic

But I need 1.63. What do I do wrong? I use arch linux, my current cmake version is 3.8.2.

Edit

I updated 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 now understands I want to use an older version, but still can't find it. Did I do another mistake? I installed the older package by extracting the by packman cached version from /var/cache/pacman/pkg/' and extracted it to/opt/oldlibs/boost/`.

The usr directory looks like this:

usr
├── oldlib
│   ├── boost
│   │   ├── bin
│   │   ├── include (contains all header files)
│   │   ├── lib (contains all libraries, static and shared)
│   │   └── share

This is a part of the cmake output:

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)

I also tried running cmake with the option -DCMAKE_PREFIX_PATH=/opt/oldlibs/boost/lib and varying the path. It didn't change anything.

Upvotes: 0

Views: 2037

Answers (1)

user268396
user268396

Reputation: 12006

Your find_package() seems wrong, as you don't specify a version requirement on it:

find_package(Boost REQUIRED regex date_time system filesystem thread graph program_options serialization iostreams chrono atomic)

This asks cmake for Boost with the understanding that "any Boost is fine". This assumption does not hold, you know it, and so you should specify the version you want:

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)

If that still doesn't work (because cmake's versioning conventions lead it to prefer the newer Boost under the assumption that newer is better...), then you can specify EXACT to force the version.

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)

This is all documented here.

Upvotes: 1

Related Questions