The BoostRoot points to "" empty directory, where do I change its value to set a permanent directory?

Viewed 77

So I could not compile the c++ code with this in its CMakeList.txt

find_package(Boost REQUIRED COMPONENTS program_options)

due to error output

Imported target "Boost::program_options" includes non-existent path

"/include"

in its INTERFACE_INCLUDE_DIRECTORIES.

I print out the variables BOOST_ROOT and Boost_INCLUDE_DIRS in boost_program_options-config.cmake (it is the file which the compiler error points to )

It turns out that BOOST_ROOT is "" and Boost_INCLUDE_DIRS points to "/include"

I believe this is the reason, the directory of the boost include file is under path /usr/include

What could I to set the BOOST_ROOT parameter permanently for all future build or better ways to fix this problem?

Following fellow coder's advises, I reinstalled the boost but the build error still persists.

What I did to reinstall boost was

  1. remove the boost( I only have boost 1.71 install), commands on Ubuntu20.04 Terminal are:

:~$ sudo apt-get autoremove libboost1.71-dev

  1. reinstall boost, commands are:

:~$ sudo apt-get install libboost-all-dev

I also checked the cmake version and it is cmake 3.16.3

The code is the ROS2's Nav2 package. With ROS2 already installed and running prefectly, the build commands I use to build the Nav2 package is

:~$ colcon build --symlink-install

This is the command that throws out the error

Imported ... Boost::program_options ... non-existent path ... INTERFACE_INCLUDE_DIRECTORIES

thanks ahead!

1 Answers

OK, so after some investigation over weekend the answer to resolving the problem becomes clear.

The cause of distress is two folds.

Firstly, ubuntu has shortcut to /usr/lib as lib at root directory /, which is the folder /lib.

Secondly, ubuntu's root directory does not have a /include folder that suppose to have all the headers etc.

So when building your codes. The cmake sets all your CMAKE_CURRENT_LIST_DIR with prefix "" instead of /usr

this is problematic because if you look at boost_program_options-config.cmake. The _BOOST_INCLUDEDIR is the value that sets the INTERFACE_INCLUDE_DIRECTORIES.

However, _BOOST_INCLUDEDIR is in turn set by CMAKE_CURRENT_LIST_DIR as prefix. Therefore you get a /<subfix> instead of /usr/<subfix>as your boost include folder directory.

cmake would find no such include folder of such directory. Thus outputting the question's error message.

To solve is simple, either delete the shortcut folder at root, or create shortcut folder that is linked to /usr/include .

Related