traversaro / drake-lite-cmake

Reduced (lite) unofficial version of drake (https://drake.mit.edu/) that can be built with CMake.
11 stars 0 forks source link

Fix Windows compilation #3

Closed traversaro closed 4 years ago

traversaro commented 4 years ago

Back in February I briefly tried to compile the existing codebase with the MSVC compiler, but there were some non-trivial issue, in particular the use of the non portable __PRETTY_FUNCTION__, that is implemented in GCC and Clang, but it is not part of the C++ standard (see a related discussion in https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/RKnK3MJpol8) in the key header value.h. Visual Studio provides an alternative __FUNCSIG__ but the content reported is quite different (see https://quuxplusone.github.io/blog/2018/08/22/puts-pretty-function/), so it basically would require rewriting the relevant code in Drake.

For this reason the strategy in the first place was to try to use the clang_cl_x64 toolset provided inside Visual Studio, to compile the drake library with clang_cl_x64, but producing it in a form that it can be linked in a MSVC-compiled project (as long as they don't instantiate the non-supported functions in value.h or in other headers). An alternative use case is to write drake + drake-using plugins using clang_cl_x64, that then can be loaded in programs compiled with MSVC (for example to develop a ignition-physics plugin based on Drake, that can be loaded in a MSVC-compiled Ignition Gazebo).

Compilation with clang_cl_x64 was working fine locally with VS 16.4, but some workarounds were needed (see https://developercommunity.visualstudio.com/content/problem/599908/cmake-clang-cl-x64-toolset-cannot-find-clang-clexe.html). Furthermore, the Debug build on GitHub Actions (see ) was failing due to LLVM remaining out of memory when compiling the https://github.com/traversaro/drake-lite-cmake/runs/478374754 the multibody_tree.cc compilation unit. For this reason, it may be worth to try again now to work on this, now that VS 16.5 should have fixed all the need for workarounds with clang_cl_x64, and that recent changes in Drake (in particular related https://github.com/RobotLocomotion/drake/issues/12814) could have changed the amount of memory necessary to compile multibody_tree.cc (so waiting for https://github.com/traversaro/drake-lite-cmake/issues/5).

traversaro commented 4 years ago

Apparently updating to a recent version of Drake did not solve the LLVM out of memory error in Debug builds, so for now I just disabled Windows|Debug build on GitHub Actions and opened a separated issue in https://github.com/traversaro/drake-lite-cmake/issues/7 .

However, updating to a recent commit created actual some compilation problems, see:

2020-04-11T15:42:10.0028110Z C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.25.28610\include\yvals_core.h(690,7): message : expanded from macro '_CXX17_DEPRECATE_RESULT_OF' [D:\a\drake-lite-cmake\drake-lite-cmake\build\drake-lite-cmake.vcxproj]
2020-04-11T15:42:10.0274127Z D:\a\drake-lite-cmake\drake-lite-cmake\build\drake\common\polynomial.cc(650,12): error : use of undeclared identifier 'accumulate' [D:\a\drake-lite-cmake\drake-lite-cmake\build\drake-lite-cmake.vcxproj]

However, this seems to quite a typical error of using the std::accumulate function without declaring it, even if I am not sure why it is working correctly on Ubuntu/macOs .

traversaro commented 4 years ago

For this reason the strategy in the first place was to try to use the ClangCltoolset provided inside Visual Studio, to compile the drake library with ClangCl, but producing it in a form that it can be linked in a MSVC-compiled project (as long as they don't instantiate the non-supported functions in value.h or in other headers).

Apparently this is not possible, as the header with the problematic use of __PRETTY_FUNCTION__ is transitively included even by a minimal example that just includes:

#include "drake/systems/analysis/simulator.h"
#include "drake/systems/framework/leaf_system.h"

see the failing build of the examples using MSVC with v142 toolset against drake-lite-cmake compile with ClangCl toolset: https://github.com/traversaro/drake-lite-cmake/runs/579393366?check_suite_focus=true#step:16:148 .

So for now we just document and target the following use case:

An alternative use case is to write drake + drake-using plugins using clang_cl_x64, that then can be loaded in programs compiled with MSVC (for example to develop a ignition-physics plugin based on Drake, that can be loaded in a MSVC-compiled Ignition Gazebo).

traversaro commented 4 years ago

Apparently updating to a recent version of Drake did not solve the LLVM out of memory error in Debug builds, so for now I just disabled Windows|Debug build on GitHub Actions and opened a separated issue in #7 .

However, updating to a recent commit created actual some compilation problems, see:

2020-04-11T15:42:10.0028110Z C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.25.28610\include\yvals_core.h(690,7): message : expanded from macro '_CXX17_DEPRECATE_RESULT_OF' [D:\a\drake-lite-cmake\drake-lite-cmake\build\drake-lite-cmake.vcxproj]
2020-04-11T15:42:10.0274127Z D:\a\drake-lite-cmake\drake-lite-cmake\build\drake\common\polynomial.cc(650,12): error : use of undeclared identifier 'accumulate' [D:\a\drake-lite-cmake\drake-lite-cmake\build\drake-lite-cmake.vcxproj]

However, this seems to quite a typical error of using the std::accumulate function without declaring it, even if I am not sure why it is working correctly on Ubuntu/macOs .

This problem was reported upstream in https://github.com/RobotLocomotion/drake/pull/13046 .