How to specify the path of Boost
I'm trying to cross-compile ROS Base from source.
I've cross-compiled the Boost 1.58.0 and installed it at /usr/local/boost
, which contains include/boost
and lib
.
Also, I wrote
SET(BOOST_ROOT "/usr/local/boost")
SET(BOOST_INCLUDEDIR "/usr/local/boost/include")
SET(BOOST_LIBRARYDIR "/usr/local/boost/lib")
into the CMakeLists.txt
of cpp_common
, so it becomes as below:
cmake_minimum_required(VERSION 2.8.3)
project(cpp_common)
SET (BOOST_ROOT "/usr/local/boost")
SET (BOOST_INCLUDEDIR "/usr/local/boost/include")
SET (BOOST_LIBRARYDIR "/usr/local/boost/lib")
find_package(Boost REQUIRED COMPONENTS system thread)
find_package(console_bridge REQUIRED)
find_package(catkin REQUIRED)
And I created a file named test.cmake
as below:
# this one is important
SET(CMAKE_SYSTEM_NAME Linux)
#this one not so much
SET(CMAKE_SYSTEM_VERSION 1)
# Set the target architecture
set(CMAKE_LIBRARY_ARCHITECTURE arm-linux-gnueabihf)
# where is the target environment
SET(CMAKE_FIND_ROOT_PATH "/usr/arm-linux-gnueabihf") # no slash "/" at the end
# specify the cross compiler
SET(CMAKE_C_COMPILER /usr/bin/arm-linux-gnueabihf-gcc-5)
SET(CMAKE_CXX_COMPILER /usr/bin/arm-linux-gnueabihf-g++-5)
# Set compiler flag
SET(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} --sysroot=${CMAKE_FIND_ROOT_PATH}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --sysroot=${CMAKE_FIND_ROOT_PATH}")
# Have to set this one to BOTH, to allow CMake to find rospack
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
However, when I executed the command ./src/catkin/bin/catkin_make_isolated -DCMAKE_TOOLCHAIN_FILE=/home/zyh/ros_base/test2.cmake --install -DCMAKE_BUILD_TYPE=Release
to compile the ROS, I still get the error:
==> Processing catkin package: 'cpp_common'
==> Building with env: '/home/zyh/ros_base/install_isolated/env.sh'
==> cmake /home/zyh/ros_base/src/roscpp_core/cpp_common -DCATKIN_DEVEL_PREFIX=/home/zyh/ros_base/devel_isolated/cpp_common -DCMAKE_INSTALL_PREFIX=/home/zyh/ros_base/install_isolated -DCMAKE_TOOLCHAIN_FILE=/home/zyh/ros_base/test2.cmake -DCMAKE_BUILD_TYPE=Release -G Unix Makefiles in '/home/zyh/ros_base/build_isolated/cpp_common'
CMake Warning at /usr/share/cmake-3.5/Modules/FindBoost.cmake:725 (message):
Imported targets not available for Boost version
Call Stack (most recent call first):
/usr/share/cmake-3.5/Modules/FindBoost.cmake:763 (_Boost_COMPONENT_DEPENDENCIES)
/usr/share/cmake-3.5/Modules/FindBoost.cmake:1332 (_Boost_MISSING_DEPENDENCIES)
CMakeLists.txt:6 (find_package)
CMake Warning at /usr/share/cmake-3.5/Modules/FindBoost.cmake:725 (message):
Imported targets not available for Boost version
Call Stack (most recent call first):
/usr/share/cmake-3.5/Modules/FindBoost.cmake:763 (_Boost_COMPONENT_DEPENDENCIES)
/usr/share/cmake-3.5/Modules/FindBoost.cmake:1332 (_Boost_MISSING_DEPENDENCIES)
CMakeLists.txt:6 (find_package)
CMake Error at /usr/share/cmake-3.5/Modules/FindBoost.cmake:1677 (message):
Unable to find the requested Boost libraries.
Unable to find the Boost header files. Please set BOOST_ROOT to the root
directory containing Boost or BOOST_INCLUDEDIR to the directory containing
Boost's headers.
Call Stack (most recent call first):
CMakeLists.txt:6 (find_package)
Try writing the Boost-related variables like so:
set(Boost_INCLUDE_DIR /usr/local/boost/include) set(Boost_LIBRARY_DIR /usr/local/boost/lib)
Also, I have them in the toolchain file rather than cpp_common's CMake file, I suggest you change that if you are building the whole bare-bones variant.
@jotator thanks a lot, it works perfectly.
No problem :) Did you have to put it inside the toolchain file or was cpp_common's CMakeLists.txt enough?