2

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!

  • In Windows, there is a CMake GUI. The last resort is to fix such variables manually. In Linux, there is ccmake. I believe it provides a similar option. Manual settings will be kept as long as you don't delete the build dir. where CMake caches its settings. You also can try to fix it with [CMAKE_PREFIX_PATH](https://cmake.org/cmake/help/latest/variable/CMAKE_PREFIX_PATH.html). (It can be provided as environment variable as well.) – Scheff's Cat Nov 10 '21 at 06:57
  • @Scheff'sCat I use colcon build --symlink-install to build the codes. I do not know how to change environmental or global variables with Cmake GUI. Please tell or a link on how to do so. Or if Is there a .cmake I could change? – jojo_Aero_smith_the_dummy Nov 10 '21 at 07:08
  • Sorry. I spotted `CMakeLists.txt` and immediately assumed `CMake`. (Not to mention that you tagged [tag:cmake].) ;-) Maybe, [edit] your question and describe in more detail how you actually intend to build your sources. I've never heard about _colcon build --symlink-install_... – Scheff's Cat Nov 10 '21 at 07:11
  • Maybe, mention your platform as well. However, [Environment variable](https://en.wikipedia.org/wiki/Environment_variable)s can be defined on Windows as well as on Linux. You can do it in the console you're working in. In Windows, env. vars can be set permanently using the System Settings (for a specific user or for every user). In Linux, such permanent setting can be achieved by editing the start script e.g. `~/.login` or `~/.bashrc`. – Scheff's Cat Nov 10 '21 at 07:14
  • As I [commented](https://stackoverflow.com/questions/69897625/how-to-solve-imported-target-boostprogram-options-includes-non-existent-pat#comment123558165_69897625) in you previous question, incorrect content of Boost config scripts means **broken Boost installation**. With given scripts you can do nothing to fix the problem: you need to properly (re-)install Boost. If you think that you have installed Boost properly, then describe how **exactly** have you installed Boost: which commands you run, with which parameters, and so on. – Tsyvarev Nov 10 '21 at 08:37
  • The boost cmake configuration does not seem to set `Boost_ROOT`; Afaik this variable is only hint for `find_package(Boost)` added in cmake version 3.12. Btw: have you by chance used the empty `--prefix` when installing boost? at least my boost build on windows seems to prefer the original install directory over the current location, should it still exist which seems to be the only thing that could result in this issue. (there's a check `if(EXISTS "D:/somedir/boost/lib/cmake")`, so if this looks like `if (EXISTS "/")` for you, my assumption is correct) – fabian Nov 10 '21 at 20:40
  • @fabian the boost was installed along with ubuntu I believe or with apt fix install. I did not install it specifically. The boost version is " 1.17 amd64 " and cmake is " 3.16.3 ". – jojo_Aero_smith_the_dummy Nov 12 '21 at 02:23
  • @Tsyvarev So I did the following commands: ##[remove the boost( I only have 1.71 install), commands are:] >> sudo apt-get autoremove libboost1.71-dev ##[reinstall boost, commands are:] >> sudo apt-get install libboost-all-dev ########### the build error is still the same unfortunately. – jojo_Aero_smith_the_dummy Nov 12 '21 at 02:29

1 Answers1

1

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 .