nicolapiccinelli / libmpc

libmpc++ is a C++ header-only library to solve linear and non-linear MPC
https://altairlab.gitlab.io/optcontrol/libmpc/
MIT License
138 stars 21 forks source link

Linking library from external cmake project #6

Closed Veng97 closed 1 year ago

Veng97 commented 1 year ago

Hello,

I have an issue trying to use this library, i might be doing something wrong in my CMakeLists.txt file, but i have no idea if that's the underlying issue.

Setup: Compiling with C++20 Using target_link_library(my_application mpc++)

Its throwing the following errors: In file included from /usr/local/include/mpc/NLMPC.hpp:3: In file included from /usr/local/include/mpc/IMPC.hpp:3: /usr/local/include/mpc/IDimensionable.hpp:22:23: error: a non-type template parameter cannot have type 'mpc::MPCSize' template ^ /usr/local/include/mpc/IDimensionable.hpp:87:19: error: expected '(' for function-style cast or type construction double)>;


/usr/local/include/mpc/IDimensionable.hpp:90:31: error: expected expression
            cvec<sizer.ineq> &,
                              ^
/usr/local/include/mpc/IDimensionable.hpp:94:19: error: expected '(' for function-style cast or type construction
            double)>;
            ~~~~~~^
/usr/local/include/mpc/IDimensionable.hpp:97:29: error: expected expression
            cvec<sizer.eq> &,
                            ^
/usr/local/include/mpc/IDimensionable.hpp:102:29: error: expected expression
            cvec<sizer.nx> &,
                            ^
/usr/local/include/mpc/IDimensionable.hpp:107:29: error: expected expression
            cvec<sizer.ny> &,
                            ^
In file included from /SAM/Workspace/src/control_stack/path_tracking/src/mpc_node.cpp:1:
In file included from /SAM/Workspace/src/control_stack/path_tracking/include/mpc/mpc.hpp:5:
In file included from /usr/local/include/mpc/NLMPC.hpp:3:
In file included from /usr/local/include/mpc/IMPC.hpp:4:
In file included from /usr/local/include/mpc/IOptimizer.hpp:3:
/usr/local/include/mpc/IComponent.hpp:21:23: error: a non-type template parameter cannot have type 'mpc::MPCSize'
    template <MPCSize sizer>
                      ^
In file included from /SAM/Workspace/src/control_stack/path_tracking/src/mpc_node.cpp:1:
In file included from /SAM/Workspace/src/control_stack/path_tracking/include/mpc/mpc.hpp:5:
In file included from /usr/local/include/mpc/NLMPC.hpp:3:
In file included from /usr/local/include/mpc/IMPC.hpp:4:
/usr/local/include/mpc/IOptimizer.hpp:20:23: error: a non-type template parameter cannot have type 'mpc::MPCSize'
    template <MPCSize sizer>
                      ^
In file included from /SAM/Workspace/src/control_stack/path_tracking/src/mpc_node.cpp:1:
In file included from /SAM/Workspace/src/control_stack/path_tracking/include/mpc/mpc.hpp:5:
In file included from /usr/local/include/mpc/NLMPC.hpp:3:
/usr/local/include/mpc/IMPC.hpp:23:23: error: a non-type template parameter cannot have type 'mpc::MPCSize'
    template <MPCSize sizer>
                      ^
In file included from /SAM/Workspace/src/control_stack/path_tracking/src/mpc_node.cpp:1:
In file included from /SAM/Workspace/src/control_stack/path_tracking/include/mpc/mpc.hpp:5:
In file included from /usr/local/include/mpc/NLMPC.hpp:5:
In file included from /usr/local/include/mpc/NLMPC/Constraints.hpp:3:
In file included from /usr/local/include/mpc/NLMPC/Base.hpp:4:
/usr/local/include/mpc/NLMPC/Mapping.hpp:20:23: error: a non-type template parameter cannot have type 'mpc::MPCSize'
    template <MPCSize sizer>
                      ^
/usr/local/include/mpc/NLMPC/Mapping.hpp:46:29: error: use of undeclared identifier 'ph'
            Iz2uMat.resize((ph() * nu()), (nu() * ch()));
                            ^
/usr/local/include/mpc/NLMPC/Mapping.hpp:46:36: error: use of undeclared identifier 'nu'
            Iz2uMat.resize((ph() * nu()), (nu() * ch()));
                                   ^
/usr/local/include/mpc/NLMPC/Mapping.hpp:46:44: error: use of undeclared identifier 'nu'
            Iz2uMat.resize((ph() * nu()), (nu() * ch()));
                                           ^
/usr/local/include/mpc/NLMPC/Mapping.hpp:46:51: error: use of undeclared identifier 'ch'
            Iz2uMat.resize((ph() * nu()), (nu() * ch()));
                                                  ^
/usr/local/include/mpc/NLMPC/Mapping.hpp:47:29: error: use of undeclared identifier 'nu'
            Iu2zMat.resize((nu() * ch()), (ph() * nu()));
                            ^
/usr/local/include/mpc/NLMPC/Mapping.hpp:47:36: error: use of undeclared identifier 'ch'
            Iu2zMat.resize((nu() * ch()), (ph() * nu()));
                                   ^
In file included from /SAM/Workspace/src/control_stack/path_tracking/src/mpc/mpc.cpp:1:
In file included from /SAM/Workspace/src/control_stack/path_tracking/include/mpc/mpc.hpp:5:
In file included from /usr/local/include/mpc/NLMPC.hpp:3:
In file included from /usr/local/include/mpc/IMPC.hpp:3:
/usr/local/include/mpc/IDimensionable.hpp:22:23: error: a non-type template parameter cannot have type 'mpc::MPCSize'
    template <MPCSize sizer>
                      ^
/usr/local/include/mpc/IDimensionable.hpp:87:19: error: expected '(' for function-style cast or type construction
            double)>;
            ~~~~~~^
/usr/local/include/mpc/IDimensionable.hpp:90:31: error: expected expression
            cvec<sizer.ineq> &,
                              ^
/usr/local/include/mpc/IDimensionable.hpp:94:19: error: expected '(' for function-style cast or type construction
            double)>;
            ~~~~~~^
/usr/local/include/mpc/IDimensionable.hpp:97:29: error: expected expression
            cvec<sizer.eq> &,
                            ^
/usr/local/include/mpc/IDimensionable.hpp:102:29: error: expected expression
            cvec<sizer.nx> &,
                            ^
/usr/local/include/mpc/IDimensionable.hpp:107:29: error: expected expression
            cvec<sizer.ny> &,
                            ^
In file included from /SAM/Workspace/src/control_stack/path_tracking/src/mpc/mpc.cpp:1:
In file included from /SAM/Workspace/src/control_stack/path_tracking/include/mpc/mpc.hpp:5:
In file included from /usr/local/include/mpc/NLMPC.hpp:3:
In file included from /usr/local/include/mpc/IMPC.hpp:4:
In file included from /usr/local/include/mpc/IOptimizer.hpp:3:
/usr/local/include/mpc/IComponent.hpp:21:23: error: a non-type template parameter cannot have type 'mpc::MPCSize'
    template <MPCSize sizer>
                      ^
In file included from /SAM/Workspace/src/control_stack/path_tracking/src/mpc/mpc.cpp:1:
In file included from /SAM/Workspace/src/control_stack/path_tracking/include/mpc/mpc.hpp:5:
In file included from /usr/local/include/mpc/NLMPC.hpp:3:
In file included from /usr/local/include/mpc/IMPC.hpp:4:
/usr/local/include/mpc/IOptimizer.hpp:20:23: error: a non-type template parameter cannot have type 'mpc::MPCSize'
    template <MPCSize sizer>
                      ^
/usr/local/include/mpc/NLMPC/Mapping.hpp:47:44: error: use of undeclared identifier 'ph'
            Iu2zMat.resize((nu() * ch()), (ph() * nu()));
                                           ^
/usr/local/include/mpc/NLMPC/Mapping.hpp:47:51: error: use of undeclared identifier 'nu'
            Iu2zMat.resize((nu() * ch()), (ph() * nu()));
                                                  ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
In file included from /SAM/Workspace/src/control_stack/path_tracking/src/mpc/mpc.cpp:1:
In file included from /SAM/Workspace/src/control_stack/path_tracking/include/mpc/mpc.hpp:5:
In file included from /usr/local/include/mpc/NLMPC.hpp:3:
/usr/local/include/mpc/IMPC.hpp:23:23: error: a non-type template parameter cannot have type 'mpc::MPCSize'
    template <MPCSize sizer>
                      ^
In file included from /SAM/Workspace/src/control_stack/path_tracking/src/mpc/mpc.cpp:1:
In file included from /SAM/Workspace/src/control_stack/path_tracking/include/mpc/mpc.hpp:5:
In file included from /usr/local/include/mpc/NLMPC.hpp:5:
In file included from /usr/local/include/mpc/NLMPC/Constraints.hpp:3:
In file included from /usr/local/include/mpc/NLMPC/Base.hpp:4:
/usr/local/include/mpc/NLMPC/Mapping.hpp:20:23: error: a non-type template parameter cannot have type 'mpc::MPCSize'
    template <MPCSize sizer>
                      ^
/usr/local/include/mpc/NLMPC/Mapping.hpp:46:29: error: use of undeclared identifier 'ph'
            Iz2uMat.resize((ph() * nu()), (nu() * ch()));
                            ^
/usr/local/include/mpc/NLMPC/Mapping.hpp:46:36: error: use of undeclared identifier 'nu'
            Iz2uMat.resize((ph() * nu()), (nu() * ch()));
                                   ^
/usr/local/include/mpc/NLMPC/Mapping.hpp:46:44: error: use of undeclared identifier 'nu'
            Iz2uMat.resize((ph() * nu()), (nu() * ch()));
                                           ^
/usr/local/include/mpc/NLMPC/Mapping.hpp:46:51: error: use of undeclared identifier 'ch'
            Iz2uMat.resize((ph() * nu()), (nu() * ch()));
                                                  ^
/usr/local/include/mpc/NLMPC/Mapping.hpp:47:29: error: use of undeclared identifier 'nu'
            Iu2zMat.resize((nu() * ch()), (ph() * nu()));
                            ^
/usr/local/include/mpc/NLMPC/Mapping.hpp:47:36: error: use of undeclared identifier 'ch'
            Iu2zMat.resize((nu() * ch()), (ph() * nu()));
                                   ^
/usr/local/include/mpc/NLMPC/Mapping.hpp:47:44: error: use of undeclared identifier 'ph'
            Iu2zMat.resize((nu() * ch()), (ph() * nu()));
                                           ^
/usr/local/include/mpc/NLMPC/Mapping.hpp:47:51: error: use of undeclared identifier 'nu'
            Iu2zMat.resize((nu() * ch()), (ph() * nu()));
                                                  ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
Veng97 commented 1 year ago

My gcc and clang versions were too old (i tried them both). I was trying to compile with an older version of gcc than the one stated in the README :dancers: I use Clang for my project, so i updated the Clang to version 15 (default shipped with ubuntu20.04 was Clang-10), this also resolved the error! :)