Yarp: Unable to include LogStream with CasAdi

Created on 25 Nov 2020  Â·  3Comments  Â·  Source: robotology/yarp

Describe the bug

If I include

#include <casadi/casadi.hpp>
#include <yarp/os/LogStream.h>

the following error occurs while compiles:

In file included from /home/giuseppe/robotology-superbuild/build/install/include/yarp/os/all.h:26,
                 from /home/giuseppe/Desktop/IronCub/element_transition-maneouvers/modules/point_mass_opt_test/pointMassOptimizer/include/Solver.h:13,
                 from /home/giuseppe/Desktop/IronCub/element_transition-maneouvers/modules/point_mass_opt_test/pointMassOptimizer/src/Solver.cpp:9:
/home/giuseppe/robotology-superbuild/build/install/include/yarp/os/LogStream.h:238:22: error: redefinition of ‘template<class T> std::ostream& std::operator<<(std::ostream&, const std::vector<T>&)’
  238 | inline std::ostream& std::operator<<(std::ostream& os, const std::vector<T>& t)
      |                      ^~~
In file included from /home/giuseppe/git_repos/casadi/build/install/include/casadi/core/matrix_fwd.hpp:29,
                 from /home/giuseppe/git_repos/casadi/build/install/include/casadi/core/sx_elem.hpp:33,
                 from /home/giuseppe/git_repos/casadi/build/install/include/casadi/core/core.hpp:30,
                 from /home/giuseppe/git_repos/casadi/build/install/include/casadi/casadi.hpp:29,
                 from /home/giuseppe/Desktop/IronCub/element_transition-maneouvers/modules/point_mass_opt_test/pointMassOptimizer/include/Solver.h:12,
                 from /home/giuseppe/Desktop/IronCub/element_transition-maneouvers/modules/point_mass_opt_test/pointMassOptimizer/src/Solver.cpp:9:
/home/giuseppe/git_repos/casadi/build/install/include/casadi/core/casadi_misc.hpp:430:12: note: ‘template<class T> std::ostream& std::operator<<(std::ostream&, const std::vector<T>&)’ previously declared here
  430 |   ostream& operator<<(ostream& stream, const vector<T>& v) {
      |            ^~~~~~~~
make[2]: *** [modules/point_mass_opt_test/pointMassOptimizer/CMakeFiles/TrajOptSolver.dir/build.make:83: modules/point_mass_opt_test/pointMassOptimizer/CMakeFiles/TrajOptSolver.dir/src/Solver.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:361: modules/point_mass_opt_test/pointMassOptimizer/CMakeFiles/TrajOptSolver.dir/all] Error 2
make: *** [Makefile:150: all] Error 2

Configuration (please complete the following information):

  • OS: Ubuntu 20.04
  • yarp version: 3.4

    • compiler: gcc version 9.3.0

Library - YARP_os Duplicate

Most helpful comment

Thanks for opening the issue! We had a similar discussion in https://github.com/robotology/yarp/issues/2067 .

All 3 comments

Unfortunately, both yarp and casadi expand std namespace

casadi

https://github.com/casadi/casadi/blob/fadc86444f3c7ab824dc3f2d91d4c0cfe7f9dad5/casadi/core/casadi_misc.hpp#L428-L433

yarp

https://github.com/robotology/yarp/blob/13d2bc8ea92621b29055d10c6dbc43809f35c1b0/src/libYARP_os/src/yarp/os/LogStream.h#L28-L31

Probably the fastest solution avoids using LogStream in your application

cc @traversaro

Thanks for opening the issue! We had a similar discussion in https://github.com/robotology/yarp/issues/2067 .

That's the same bug, I'm closing this in favour of #2067

Was this page helpful?
0 / 5 - 0 ratings