导入 cstring 失败:包含 <cstring> 错误

Importing cstring fails: include <cstring> error

我正在 Ubuntu 16.04 上使用 ROS 和 C++ 进行一个小组项目。一切正常,直到两周前我收到此错误 突然发消息:

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/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/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/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));

作为 C++ 和 ROS 的新手,我的第一个想法是我安装/删除了一些包,搞砸了。所以我尝试重新安装整个ros框架。没用,所以我写了一些小程序 这(我认为)显示了我的问题所在。我不能包含 <cstring>:

#include <cstring>

int main(int argc, char** argv)
{
  return 0;
}

当用 g++ -Wall a.cpp -o atest 编译时,我得到了一个 2500 row error message

现在我认为 cstring 可能有点问题,但遗憾的是我不知道如何解决它。 我的谷歌搜索表明 locate cstring | grep include 可能是感兴趣的:

/usr/include/boost/compatibility/cpp_c_headers/cstring
/usr/include/boost/python/docstring_options.hpp
/usr/include/boost/test/utils/basic_cstring
/usr/include/boost/test/utils/basic_cstring/basic_cstring.hpp
/usr/include/boost/test/utils/basic_cstring/basic_cstring_fwd.hpp
/usr/include/boost/test/utils/basic_cstring/bcs_char_traits.hpp
/usr/include/boost/test/utils/basic_cstring/compare.hpp
/usr/include/boost/test/utils/basic_cstring/io.hpp
/usr/include/c++/4.8/cstring
/usr/include/c++/5/cstring
/usr/include/qt4/Qt/q3cstring.h
/usr/include/qt4/Qt3Support/q3cstring.h

可能是安装了两个版本的C++有问题?

我快要设置我的系统了 从头开始所以你们是我最后的希望。

感谢@molbdnilo 和@Konrad Rudolph 我发现我的 /usr/include/string.h(这是一个 C 头文件)试图导入 /usr/include/c++/5/iostream(这是一个 C++ 库)。 在 vim diff 与工作 string.h 之后,我删除了不同的行,这只是 iostream 的 include 语句。

正如@digitalarbeiter 所建议的那样,手动更改此类文件中的某些代码通常不是一个好主意,所以我重新安装了 libc6-dev

sudo apt-get install libc6-dev --reinstall

它仍然有效。

我仍然不知道这是怎么发生的。 4月份编辑的文件,10月份出现错误。总之感谢大家的帮助!