免责声明 - 我完全不了解 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/