opensim-org / opensim-core

SimTK OpenSim C++ libraries and command-line applications, and Java/Python wrapping.
https://opensim.stanford.edu
Apache License 2.0
785 stars 318 forks source link

Most C++ Examples Fail To Compile #3929

Open alexbeattie42 opened 6 days ago

alexbeattie42 commented 6 days ago

Problem

Most of the C++ examples fail to compile independently. OpenSim is using std::conditional_t in Array.h. This is a feature that was introduced in c++14 which is shown here in the helper types section. The cmake files for most of the examples are set to c++11 and therefore do not compile independently and produce the following error:

~/opensim-core/sdk/include/OpenSim/Common/Array.h:583:26: error: ‘conditional_t’ in namespace ‘std’ does not name a template type; did you mean ‘conditional’?
  583 |     using storage = std::conditional_t<
      |                          ^~~~~~~~~~~~~
      |                          conditional
~/opensim-core/sdk/include/OpenSim/Common/Array.h:589:5: error: ‘storage’ does not name a type
  589 |     storage _storage;
      |     ^~~~~~~
~/opensim-core/sdk/include/OpenSim/Common/Array.h: In constructor ‘OpenSim::Array<T>::Array(T, int, int)’:
~/opensim-core/sdk/include/OpenSim/Common/Array.h:66:9: error: ‘_storage’ was not declared in this scope
   66 |         _storage.reserve(aCapacity);
      |         ^~~~~~~~

Note: The examples compile within the OpenSim build because there is an override to c++14 in one of the top level CMakeLists.txt files for OpenSim.

Solution

Change the line for set(CMAKE_CXX_STANDARD 11) to at least set(CMAKE_CXX_STANDARD 14) in each examples CMakeLists.txt

I can submit a pull request that updates all of the examples CMakeLists.txt files to c++14 if it would be helpful.

nickbianco commented 5 days ago

That would be great, @alexbeattie42! Thanks again.