4

I need help solving this cmake boost python3 find problem when trying to compile cv_bridge from ros2, which uses a build tool called colcon and in turn CMake. The colcon build error message:

> colcon build --symlink-install --merge-install
...    
--- stderr: cv_bridge
    CMake Error at C:/Program Files/CMake/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
      Could NOT find Boost (missing: python3) (found version "1.76.0")
    Call Stack (most recent call first):
      C:/Program Files/CMake/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
      C:/Program Files/CMake/share/cmake-3.22/Modules/FindBoost.cmake:2360 (find_package_handle_standard_args)
      CMakeLists.txt:32 (find_package)

What I have tried:

  • Installing different versions of boost: 1.58, 1.67, 1.76
  • Adding to Boost_INCLUDE_DIRS the path to the boost libraries in the CMakeLists.txt of cv_bridge:
     if(NOT ANDROID)
          find_package(PythonLibs)
          list(APPEND Boost_INCLUDE_DIRS "C:/Program Files/boost/boost_1_76_0")
          list(APPEND Boost_INCLUDE_DIRS "C:/Program Files/boost/boost_1_76_0/stage/lib")
  • Renaming the libboost_python38-vc142-mt-gd-x64-1_76.lib to libboost_python38.lib and libboost_python3.lib
  • Compiling Boost from source with bootstrap.bat and b2 or installing with the zip file.
  • Looked for answers here and elsewhere, which led me to tried things above

I have run out of ideas, please any help will be greatly appreciated!

Lora
  • 65
  • 1
  • 5
  • Try the config version `find_package` to locate boost. Set `Boost_ROOT` before using `find_package`; alternatively add the directory you installed boost to using b2 (`.\b2 ... "--prefix=some/path" ... install`) to `CMAKE_PREFIX_PATH`. `find_package(Boost REQUIRED COMPONENTS python CONFIG)`. Furthermore note that [the `FindPythonLibs` module](https://cmake.org/cmake/help/latest/module/FindPythonLibs.html) is deprecated since cmake 3.12 – fabian Nov 10 '21 at 20:18
  • Thanks fabian! I tried to set Boost_ROOT, for which the policy CMP0074 needed as well to be set to NEW with no luck. Likewise adding `C:\Program Files\boost\boost_1_76_0` to `CMAKE_PREFIX_PATH` did not work. Also the config version did not work. The config version failed to find `FindPython3Config.cmake` since it does not exist. I found this [thread](https://github.com/boostorg/boost_install/issues/) where it seems that cmake config stops looking where its told to with boost 1.70 and above... – Lora Nov 12 '21 at 17:21

3 Answers3

4

I got a similar issue while compiling ros noetic on my Fedora. It was able to find Boost 1.76.0 so I thought the issue should be with the python component. I guess it was not able to find the right libboost_python version. So when I checked for the library I found it at this location: /usr/lib64/libboost_python310.so. So I updated the cv_bridge/CMakeLists.txt to specifically use 3.10 version :

if(NOT ANDROID)
  find_package(PythonLibs)

  if(PYTHONLIBS_VERSION_STRING VERSION_LESS "3.8")
    # Debian Buster
    find_package(Boost REQUIRED python37)
  else()
    # Ubuntu Focal
    
    # Because I am using python 3.10 I updated
    # this line. If you are using a version less
    # than 3.8, then update the previous line

    # Updated line
    find_package(Boost REQUIRED python310)
  endif()
else()
find_package(Boost REQUIRED)
endif()

Setting it to specifically find the 3.10 version fixed the issue and I was able to compile.

EDIT: Didn't realize that the question was for Windows Platform but this answer may still help

1

I was able to solve it (after a few days of suffering) using precompiled Boost 1.74 and by changing the boost/python related parts of cv_bridge/CMakeLists.txt to:

...
set(BOOST_ROOT <your/path/to/boost_1_74_0>)

find_package (Python3 REQUIRED COMPONENTS Interpreter Development)
if(NOT ANDROID)
    find_package(Boost QUIET)
    if(Boost_VERSION LESS 106500)
        find_package(Boost REQUIRED python)
    else()
        # This is a bit of a hack to suppress a warning
        #   No header defined for python3; skipping header check
        # Which should only affect Boost versions < 1.67
        # Resolution for newer versions:
        #  https://gitlab.kitware.com/cmake/cmake/issues/16391
        if (Boost_VERSION LESS 106700)
            set(_Boost_PYTHON3_HEADERS "boost/python.hpp")
        endif()
        find_package(Boost COMPONENTS python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR} REQUIRED)
    endif()
else()
    find_package(Boost REQUIRED)
endif()
find_package(sensor_msgs REQUIRED)
...

Do not forget to remove build and install folders before triggering colcon build again.

RochaLBR
  • 68
  • 1
  • 7
0

I had the same problem. I tried to give the lib and include folders explicitly to cmake, so as the library itself and I also tried to rename libboost_python37-vc143-mt-x64-1_78.lib to libboost_python3.lib but non of these worked.

What worked was to simply providing the root to cmake:

cmake -DBOOST_ROOT=C:\\Boost ..

in my case C:\\Boost contains the lib and ìnclude folders that I created using:

.\b2 --with-python -j16 --prefix=C:\Boost --libdir=C:\Boost\lib --includedir=C:\Boost\include install
lcit
  • 306
  • 3
  • 12