Chen Wang
Chen Wang

Reputation: 528

Encounter "RuntimeError: The operating system's C++ standard library is not installed correctly" when build drake from source using bazel

System:Ubuntu 18.04

I am trying to build Drake from source using Bazel, I have installed the prerequisite using the provided install_prereqs.sh. However, when I am trying to build drake from source, I encounter a strange problem. It turns out to be related with the tools/workspace/pybind11/mkdoc.py file and //bindings/pydrake:generate_pybind_coverage target. The terminal output is shown below.

After I run

bazel build //bindings/pydrake:generate_pybind_coverage

an error is returned

INFO: Analyzed target //bindings/pydrake:generate_pybind_coverage (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /home/chenwang/drake/bindings/pydrake/BUILD.bazel:57:37: Action bindings/pydrake/documentation_pybind.h failed: (Exit 1): mkdoc failed: error executing command bazel-out/host/bin/tools/workspace/pybind11/mkdoc -DDRAKE_COMMON_SYMBOLIC_DETAIL_HEADER -DEIGEN_MPL2_ONLY -DHAVE_CSTDDEF '-DFMT_HEADER_ONLY=1' '-DFMT_NO_FMT_STRING_ALIAS=1' -DHAVE_SPDLOG ... (remaining 804 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
bazel-out/k8-opt/bin/bindings/pydrake/documentation_pybind.h.tmp_artifacts/mkdoc_glue.h:1:10: fatal error: 'optional' file not found
clang version 9.0.0-2~ubuntu18.04.2 (tags/RELEASE_900/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: 
 "clang" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-fsyntax-only" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "foo" "-mrelocation-model" "static" "-mthread-model" "posix" "-mdisable-fp-elim" "-fallow-editor-placeholders" "-fmath-errno" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu" "x86-64" "-dwarf-column-info" "-debugger-tuning=gdb" "-resource-dir" "lib/clang/9.0.0" "-isystem" "lcmtypes" "-isystem" "bazel-out/k8-opt/bin/lcmtypes" "-isystem" "external/lcm" "-isystem" "bazel-out/k8-opt/bin/external/lcm" "-isystem" "external/lcm/lcm" "-isystem" "bazel-out/k8-opt/bin/external/lcm/lcm" "-isystem" "external/eigen/include/_usr_include_eigen3" "-isystem" "bazel-out/k8-opt/bin/external/eigen/include/_usr_include_eigen3" "-isystem" "external/fmt/include" "-isystem" "bazel-out/k8-opt/bin/external/fmt/include" "-isystem" "external/optitrack_driver/lcmtypes" "-isystem" "bazel-out/k8-opt/bin/external/optitrack_driver/lcmtypes" "-isystem" "external/clp/include/_usr_include_coin" "-isystem" "bazel-out/k8-opt/bin/external/clp/include/_usr_include_coin" "-isystem" "external/nlopt/include" "-isystem" "bazel-out/k8-opt/bin/external/nlopt/include" "-isystem" "external/ibex/plugins/optim/src/bisector" "-isystem" "bazel-out/k8-opt/bin/external/ibex/plugins/optim/src/bisector" "-isystem" "external/ibex/plugins/optim/src/contractor" "-isystem" "bazel-out/k8-opt/bin/external/ibex/plugins/optim/src/contractor" "-isystem" "external/ibex/plugins/optim/src/data" "-isystem" "bazel-out/k8-opt/bin/external/ibex/plugins/optim/src/data" "-isystem" "external/ibex/plugins/optim/src/loup" "-isystem" "bazel-out/k8-opt/bin/external/ibex/plugins/optim/src/loup" "-isystem" "external/ibex/plugins/optim/src/strategy" "-isystem" "bazel-out/k8-opt/bin/external/ibex/plugins/optim/src/strategy" "-isystem" "external/ibex/plugins/optim/src/tools" "-isystem" "bazel-out/k8-opt/bin/external/ibex/plugins/optim/src/tools" "-isystem" "external/ibex/src/arithmetic" "-isystem" "bazel-out/k8-opt/bin/external/ibex/src/arithmetic" "-isystem" "external/ibex/src/bin" "-isystem" "bazel-out/k8-opt/bin/external/ibex/src/bin" "-isystem" "external/ibex/src/bisector" "-isystem" "bazel-out/k8-opt/bin/external/ibex/src/bisector" "-isystem" "external/ibex/src/combinatorial" "-isystem" "bazel-out/k8-opt/bin/external/ibex/src/combinatorial" "-isystem" "external/ibex/src/contractor" "-isystem" "bazel-out/k8-opt/bin/external/ibex/src/contractor" "-isystem" "external/ibex/src/data" "-isystem" "bazel-out/k8-opt/bin/external/ibex/src/data" "-isystem" "external/ibex/src/function" "-isystem" "bazel-out/k8-opt/bin/external/ibex/src/function" "-isystem" "external/ibex/src/numeric" "-isystem" "bazel-out/k8-opt/bin/external/ibex/src/numeric" "-isystem" "external/ibex/src/operators" "-isystem" "bazel-out/k8-opt/bin/external/ibex/src/operators" "-isystem" "external/ibex/src/parser" "-isystem" "bazel-out/k8-opt/bin/external/ibex/src/parser" "-isystem" "external/ibex/src/predicate" "-isystem" "bazel-out/k8-opt/bin/external/ibex/src/predicate" "-isystem" "external/ibex/src/set" "-isystem" "bazel-out/k8-opt/bin/external/ibex/src/set" "-isystem" "external/ibex/src/solver" "-isystem" "bazel-out/k8-opt/bin/external/ibex/src/solver" "-isystem" "external/ibex/src/strategy" "-isystem" "bazel-out/k8-opt/bin/external/ibex/src/strategy" "-isystem" "external/ibex/src/symbolic" "-isystem" "bazel-out/k8-opt/bin/external/ibex/src/symbolic" "-isystem" "external/ibex/src/system" "-isystem" "bazel-out/k8-opt/bin/external/ibex/src/system" "-isystem" "external/ibex/src/tools" "-isystem" "bazel-out/k8-opt/bin/external/ibex/src/tools" "-isystem" "external/ibex/interval_lib_wrapper/filib" "-isystem" "bazel-out/k8-opt/bin/external/ibex/interval_lib_wrapper/filib" "-isystem" "external/ibex/lp_lib_wrapper/clp" "-isystem" "bazel-out/k8-opt/bin/external/ibex/lp_lib_wrapper/clp" "-isystem" "external/ibex/src" "-isystem" "bazel-out/k8-opt/bin/external/ibex/src" "-isystem" "external/ibex/filibsrc-3.0.2.2" "-isystem" "bazel-out/k8-opt/bin/external/ibex/filibsrc-3.0.2.2" "-isystem" "external/ibex" "-isystem" "bazel-out/k8-opt/bin/external/ibex" "-isystem" "external/ipopt/include/_usr_include_coin" "-isystem" "bazel-out/k8-opt/bin/external/ipopt/include/_usr_include_coin" "-isystem" "external/vtk/include/vtk-8.2" "-isystem" "bazel-out/k8-opt/bin/external/vtk/include/vtk-8.2" "-isystem" "external/double_conversion/include" "-isystem" "bazel-out/k8-opt/bin/external/double_conversion/include" "-isystem" "external/libtiff/include/_usr_include_x86_64-linux-gnu" "-isystem" "bazel-out/k8-opt/bin/external/libtiff/include/_usr_include_x86_64-linux-gnu" "-isystem" "external/libjpeg/include" "-isystem" "bazel-out/k8-opt/bin/external/libjpeg/include" "-isystem" "external/libpng/include/_usr_include_libpng16" "-isystem" "bazel-out/k8-opt/bin/external/libpng/include/_usr_include_libpng16" "-isystem" "external/glew/include/_usr_include_libdrm" "-isystem" "bazel-out/k8-opt/bin/external/glew/include/_usr_include_libdrm" "-isystem" "external/opengl/include" "-isystem" "bazel-out/k8-opt/bin/external/opengl/include" "-isystem" "external/spdlog/include" "-isystem" "bazel-out/k8-opt/bin/external/spdlog/include" "-isystem" "external/yaml_cpp/include" "-isystem" "bazel-out/k8-opt/bin/external/yaml_cpp/include" "-isystem" "external/boost" "-isystem" "bazel-out/k8-opt/bin/external/boost" "-iquote" "." "-iquote" "bazel-out/k8-opt/bin" "-iquote" "external/lcm" "-iquote" "bazel-out/k8-opt/bin/external/lcm" "-iquote" "external/eigen" "-iquote" "bazel-out/k8-opt/bin/external/eigen" "-iquote" "external/fmt" "-iquote" "bazel-out/k8-opt/bin/external/fmt" "-iquote" "external/optitrack_driver" "-iquote" "bazel-out/k8-opt/bin/external/optitrack_driver" "-iquote" "external/clp" "-iquote" "bazel-out/k8-opt/bin/external/clp" "-iquote" "external/nlopt" "-iquote" "bazel-out/k8-opt/bin/external/nlopt" "-iquote" "external/ibex" "-iquote" "bazel-out/k8-opt/bin/external/ibex" "-iquote" "external/ipopt" "-iquote" "bazel-out/k8-opt/bin/external/ipopt" "-iquote" "external/vtk" "-iquote" "bazel-out/k8-opt/bin/external/vtk" "-iquote" "external/double_conversion" "-iquote" "bazel-out/k8-opt/bin/external/double_conversion" "-iquote" "external/liblz4" "-iquote" "bazel-out/k8-opt/bin/external/liblz4" "-iquote" "external/liblzma" "-iquote" "bazel-out/k8-opt/bin/external/liblzma" "-iquote" "external/zlib" "-iquote" "bazel-out/k8-opt/bin/external/zlib" "-iquote" "external/libtiff" "-iquote" "bazel-out/k8-opt/bin/external/libtiff" "-iquote" "external/libjpeg" "-iquote" "bazel-out/k8-opt/bin/external/libjpeg" "-iquote" "external/libpng" "-iquote" "bazel-out/k8-opt/bin/external/libpng" "-iquote" "external/glew" "-iquote" "bazel-out/k8-opt/bin/external/glew" "-iquote" "external/opengl" "-iquote" "bazel-out/k8-opt/bin/external/opengl" "-iquote" "external/x11" "-iquote" "bazel-out/k8-opt/bin/external/x11" "-iquote" "external/spdlog" "-iquote" "bazel-out/k8-opt/bin/external/spdlog" "-iquote" "external/tinyxml2" "-iquote" "bazel-out/k8-opt/bin/external/tinyxml2" "-iquote" "external/yaml_cpp" "-iquote" "bazel-out/k8-opt/bin/external/yaml_cpp" "-iquote" "external/boost" "-iquote" "bazel-out/k8-opt/bin/external/boost" "-D" "__MKDOC_PY__" "-D" "DRAKE_COMMON_SYMBOLIC_DETAIL_HEADER" "-D" "EIGEN_MPL2_ONLY" "-D" "HAVE_CSTDDEF" "-D" "FMT_HEADER_ONLY=1" "-D" "FMT_NO_FMT_STRING_ALIAS=1" "-D" "HAVE_SPDLOG" "-D" "SPDLOG_COMPILED_LIB" "-D" "SPDLOG_FMT_EXTERNAL" "-I" "bazel-out/k8-opt/bin/tools/install/libdrake/_virtual_includes/drake_headers" "-I" "bazel-out/k8-opt/bin/lcmtypes/_virtual_includes/lcmtypes_drake_cc" "-I" "bazel-out/k8-opt/bin/lcmtypes/_virtual_includes/acrobot" "-I" "bazel-out/k8-opt/bin/lcmtypes/_virtual_includes/allegro" "-I" "bazel-out/k8-opt/bin/lcmtypes/_virtual_includes/call_python" "-I" "bazel-out/k8-opt/bin/lcmtypes/_virtual_includes/experimental_deformable_mesh" "-I" "bazel-out/k8-opt/bin/lcmtypes/_virtual_includes/point" "-I" "bazel-out/k8-opt/bin/lcmtypes/_virtual_includes/point_cloud" "-I" "bazel-out/k8-opt/bin/lcmtypes/_virtual_includes/header" "-I" "bazel-out/k8-opt/bin/lcmtypes/_virtual_includes/quaternion" "-I" "bazel-out/k8-opt/bin/lcmtypes/_virtual_includes/image" "-I" "bazel-out/k8-opt/bin/lcmtypes/_virtual_includes/image_array" "-I" "bazel-out/k8-opt/bin/lcmtypes/_virtual_includes/contact_results_for_viz" "-I" "bazel-out/k8-opt/bin/lcmtypes/_virtual_includes/hydroelastic_contact_surface_for_viz" "-I" "bazel-out/k8-opt/bin/lcmtypes/_virtual_includes/hydroelastic_quadrature_per_point_data_for_viz" "-I" "bazel-out/k8-opt/bin/lcmtypes/_virtual_includes/point_pair_contact_info_for_viz" "-I" "bazel-out/k8-opt/bin/lcmtypes/_virtual_includes/drake_signal" "-I" "bazel-out/k8-opt/bin/lcmtypes/_virtual_includes/iiwa" "-I" "bazel-out/k8-opt/bin/lcmtypes/_virtual_includes/jaco" "-I" "bazel-out/k8-opt/bin/lcmtypes/_virtual_includes/panda" "-I" "bazel-out/k8-opt/bin/lcmtypes/_virtual_includes/planar_manipuland_status" "-I" "bazel-out/k8-opt/bin/lcmtypes/_virtual_includes/planar_gripper" "-I" "bazel-out/k8-opt/bin/lcmtypes/_virtual_includes/robot_plan" "-I" "bazel-out/k8-opt/bin/lcmtypes/_virtual_includes/schunk" "-I" "bazel-out/k8-opt/bin/lcmtypes/_virtual_includes/scope" "-I" "bazel-out/k8-opt/bin/lcmtypes/_virtual_includes/viewer" "-I" "bazel-out/k8-opt/bin/common/_virtual_includes/drake_marker_shared_library" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/x86_64-linux-gnu" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/backward" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/include/clang/9.0.0/include/" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-w" "-std=c++17" "-fdeprecated-macro" "-fdebug-compilation-dir" "/home/chenwang/.cache/bazel/_bazel_chenwang/2c3519edab348856fe150dd7d2828b4a/sandbox/linux-sandbox/7/execroot/drake" "-ferror-limit" "19" "-fmessage-length" "0" "-fobjc-runtime=gcc" "-fcxx-exceptions" "-fexceptions" "-fdiagnostics-show-option" "-fno-spell-checking" "-faddrsig" "-x" "c++" "foo"
Traceback (most recent call last):
  File "/home/chenwang/.cache/bazel/_bazel_chenwang/2c3519edab348856fe150dd7d2828b4a/sandbox/linux-sandbox/7/execroot/drake/bazel-out/host/bin/tools/workspace/pybind11/mkdoc.runfiles/drake/tools/workspace/pybind11/mkdoc.py", line 858, in <module>
    main()
  File "/home/chenwang/.cache/bazel/_bazel_chenwang/2c3519edab348856fe150dd7d2828b4a/sandbox/linux-sandbox/7/execroot/drake/bazel-out/host/bin/tools/workspace/pybind11/mkdoc.runfiles/drake/tools/workspace/pybind11/mkdoc.py", line 811, in main
    ("The operating system's C++ standard library is not "
RuntimeError: The operating system's C++ standard library is not installed correctly.
----------------
Note: The failure of target //tools/workspace/pybind11:mkdoc (with exit code 1) may have been caused by the fact that it is running under Python 3 instead of Python 2. Examine the error to determine if that appears to be the problem. Since this target is built in the host configuration, the only way to change its version is to set --host_force_python=PY2, which affects the entire build.

If this error started occurring in Bazel 0.27 and later, it may be because the Python toolchain now enforces that targets analyzed as PY2 and PY3 run under a Python 2 and Python 3 interpreter, respectively. See https://github.com/bazelbuild/bazel/issues/7899 for more information.
----------------
Target //bindings/pydrake:generate_pybind_coverage failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 1.515s, Critical Path: 1.34s
INFO: 2 processes: 2 internal.
FAILED: Build did NOT complete successfully

It seems that the reason is Clang cannot find <optional.h> file. However, I am sure that I have Clang installed and there is /usr/lib/x86_64-linux-gnu/libclang-9.so file. I have reinstalled my Clang, llvm and gcc but the problem persists.

Thank you very much for your help!

Upvotes: 0

Views: 307

Answers (1)

jwnimmer-tri
jwnimmer-tri

Reputation: 2449

The complaint is about the C++ standard library, i.e., libstc++ and its headers. The Clang compiler itself seems to be installed correctly, but it's looking for the GCC standard C++ library, and failing.

The problem might be if you have GCC 10 installed (or partially installed).

Does the https://github.com/RobotLocomotion/drake/issues/15652 advice help? Specifically:

sudo apt remove cpp-10 g++-10 gcc-10 libasan6 libgcc-10-dev libstdc++-10-dev

Possibly fully installing g++-10 (and not just gcc-10) would also solve it. I'm not sure.

Upvotes: 1

Related Questions