使用 g++ 找不到 C++ 头文件 'wchar.h' (MacOS)

标签 c++ g++

免责声明 - 我完全不了解 C++ 以及这种语言在编译/链接方面的工作方式。使用 MacOS Mojave。

对于学校类(class),我们必须使用 g++ 编译器来编译我们的 c++ 项目。 G++ 似乎安装成功; g++ -v 产生以下输出:

COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin17.5.0/8.1.0/lto-wrapper
Target: x86_64-apple-darwin17.5.0
Configured with: ../gcc-8.1.0/configure --enable-languages=c++,fortran
Thread model: posix
gcc versie 8.1.0 (GCC) 

我创建了我的第一个“hello world”程序:

#include <iostream>

using namespace std;

int main() {
    cout << "Hello, World!" << endl;
    return 0;
}

当我尝试编译此代码(使用'g++ file.cpp)时,提示以下终端输出:

In file included from /usr/local/include/c++/8.1.0/bits/postypes.h:40,
                 from /usr/local/include/c++/8.1.0/iosfwd:40,
                 from /usr/local/include/c++/8.1.0/ios:38,
                 from /usr/local/include/c++/8.1.0/ostream:38,
                 from /usr/local/include/c++/8.1.0/iostream:39,
                 from ex1.cpp:1:
/usr/local/include/c++/8.1.0/cwchar:44:10: fatale fout: wchar.h: No such file or directory
 #include <wchar.h>
          ^~~~~~~~~
compilation ended.

whcar.h 文件确实不存在于上述文件夹中。经过一番挖掘,我在以下文件夹中找到了 whcar 文件:/Library/Developer/CommandLineTools/usr/include/c++/v1

不幸的是,我有点迷茫,不知道我在说什么,考虑到一切对我来说都是全新的。

如果有人能指导我正确的方向,我将不胜感激。

亲切的问候,

泰门。

最佳答案

对我来说,重新安装 Xcode Command Line Tools 和 g++ 解决了同样的问题:

xcode-select --install
brew reinstall gcc

最后一行假设您已经安装了 homebrew .

关于使用 g++ 找不到 C++ 头文件 'wchar.h' (MacOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52295433/

相关文章:

c++ - C++中的重复符号__ZN4ArmeC1Ev错误

c++ - 有什么方法可以让 g++ 只发出与我的文件有关的警告?

c++ - g++ 生成依赖文件缺少用户定义的 header

c++ - 当 ofstream 超出范围时偶尔出现 SEG FAULT

c++ - 分配给结构映射的语法

c++ - 错误 : Initializer provided for function, __THROW __asm

c++ - 无法在原生 Dart 扩展中链接 v8

c++ - 使用 Rcpp 模块公开带有引用参数的 C++ 类方法时出错

c++ - 私有(private) C++ 成员函数与 C 函数

c++ - 在 C++ 中调用析构函数不会手动销毁对象