cstring incompability when include <ros/ros.h>

asked 2018-11-09 01:50:03 -0500

belorenz gravatar image

updated 2018-11-09 03:45:27 -0500

Out of nowhere my ros kinetic project fails building with the stacktrace below. Coulnd't figure out what the problem is, so i reinstalled my whole ros project. But the error is still the same. Seems as there is some kind of version incompability below in the stacktrace. Iam pretty new to c++ and have no clue what the problem is. Googled a lot yesterday but coulnd't find any help. What could i do to isolate the error and find the possible incompatibility?

In file included from /usr/include/c++/5/cstring:42:0,
             from /usr/include/boost/math/special_functions/detail/fp_traits.hpp:23,
             from /usr/include/boost/math/special_functions/fpclassify.hpp:20,
             from /usr/include/boost/math/special_functions/round.hpp:16,
             from /opt/ros/kinetic/include/ros/time.h:58,
             from /opt/ros/kinetic/include/ros/ros.h:38,
             from /home/benjamin/Documents/DLR/bob_ws/src/tutorial/hello_world/src/hello_world.cpp:1:
/usr/include/string.h: In function ‘size_t strlen(const char*)’:
/usr/include/string.h:395:6: error: ‘cout’ was not declared in this scope
      cout << *__s;
      ^
/usr/include/string.h:395:6: note: suggested alternative:
In file included from /opt/ros/kinetic/include/ros/time.h:54:0,
             from /opt/ros/kinetic/include/ros/ros.h:38,
             from /home/benjamin/Documents/DLR/bob_ws/src/tutorial/hello_world/src/hello_world.cpp:1:
/usr/include/c++/5/iostream:61:18: note:   ‘std::cout’
   extern ostream cout;  /// Linked to standard output
              ^
In file included from /usr/include/features.h:367:0,
             from /usr/include/stdlib.h:24,
             from /opt/ros/kinetic/include/ros/platform.h:53,
             from /opt/ros/kinetic/include/ros/time.h:53,
             from /opt/ros/kinetic/include/ros/ros.h:38,
             from /home/benjamin/Documents/DLR/bob_ws/src/tutorial/hello_world/src/hello_world.cpp:1:
/usr/include/string.h:396:6: error: expected primary-expression before ‘)’ token
      __THROW __attribute_pure__ __nonnull ((1));

EDIT: as asked I post the code and the cmakelist

hello_world.cpp:

#include <ros/ros.h>

int main(int argc, char** argv)
{
  ROS_INFO_STREAM("Welcome to the tutorials! You have successfully "
              "completed the installation.");
  return 0;
}

CMakeList:

cmake_minimum_required(VERSION 2.8.3)
project(hello_world)

add_compile_options(-std=c++14)

find_package(catkin_simple REQUIRED)
catkin_simple()

cs_add_executable(hello_world src/hello_world.cpp)

cs_install()
cs_export()
edit retag flag offensive close merge delete

Comments

Have you upgraded compilers by any chance? Does a simple test program still compile? Something like:

#include <string>
int main(int argc, char** argv)
{
  return 0;
}
gvdhoorn gravatar image gvdhoorn  ( 2018-11-09 02:34:11 -0500 )edit

Can you show us your code? even cmakelists.txt just in case

Solrac3589 gravatar image Solrac3589  ( 2018-11-09 02:40:42 -0500 )edit

@Solrac3589, the unqualified use of cout appears to occur in a system header (ie: /usr/include/string.h), not in code by @belorenz.

gvdhoorn gravatar image gvdhoorn  ( 2018-11-09 02:43:38 -0500 )edit

@gvdhoorn yes, i just saw and edited my comment.

Solrac3589 gravatar image Solrac3589  ( 2018-11-09 02:44:51 -0500 )edit

Added the code and the cmakelist. @gvdhoorn i was able compile your example without any problems. With include <ros/ros.h> on the other hand it fails like the stacktrace above.

belorenz gravatar image belorenz  ( 2018-11-09 03:46:28 -0500 )edit

If you remove -std=c++14, does it still fail?

gvdhoorn gravatar image gvdhoorn  ( 2018-11-09 05:04:46 -0500 )edit

Yes, it still fails.

belorenz gravatar image belorenz  ( 2018-11-09 05:42:10 -0500 )edit

Could isolate the problem to <cstring>. This fails with the same error message. I am fairly new to ros and to c++. What can I do to 'replace' cstring with a working one?

#include <cstring>

int main(int argc, char** argv)
{
  return 0;
}
belorenz gravatar image belorenz  ( 2018-11-09 05:58:52 -0500 )edit