string.h:没有这样的文件或目录

fatal error: string.h: No such file or directory

本文关键字:文件 string      更新时间:2023-10-16

在我的环境中,我不能包含<cstring>。我的g++版本是4.9.3 (Homebrew gcc49 4.9.3)。

错误是:

 - /usr/local/Cellar/gcc49/4.9.3/include/c++/4.9.3/cstring:42:20: fatal
   error: string.h: No such file or directory
  "#include string.h"

但是,在另一个环境(g++ 4.8.4[Ubuntu 4.8.4-2ubuntu1~14.04.3])中,我可以包含<cstring>并运行

问题是什么,我该如何解决?

[注:]也许我误解了这个问题。我试着运行我之前的代码,但是得到了这样的错误:

    /usr/local/Cellar/gcc49/4.9.3/include/c++/4.9.3/cassert:43:20: fatal error: assert.h: No such file or directory
 #include <assert.h>

那么我就不能运行我的代码了。这是c++的问题。

我检查了这篇文章,但是这个程序不工作。我已经安装了xcode-select(命令行工具),我卸载了xcode-select并重新安装了xcode-select,但它不工作。

c++不能在OSX 10.9中运行

重新安装标头修复了我的问题:

open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg