macOS 中,默认的 Clang 编译器和 Homebrew 安装的 GCC 都不包含 bits/stdc++.h 文件

在 macOS 中,默认的 Clang 编译器和 Homebrew 安装的 GCC 都不包含 bits/stdc++.h 文件,因为它是一个 非标准 的头文件,主要由 MinGW 和某些 Linux 平台的 GCC 提供。

解决方案 : 手动创建 bits/stdc++.h

1. 创建文件夹和文件

在你的 GCC 标准头文件目录中创建 bits/stdc++.h:

bash 复制代码
mkdir -p /opt/homebrew/Cellar/gcc/14.2.0_1/include/c++/14.2.0/x86_64-apple-darwin22/bits
nano /opt/homebrew/Cellar/gcc/14.2.0_1/include/c++/14.2.0/x86_64-apple-darwin22/bits/stdc++.h

2. 添加内容

在文件中添加以下内容:

cpp 复制代码
#ifndef _GLIBCXX_STD_BITS_STDCPP_H
#define _GLIBCXX_STD_BITS_STDCPP_H

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <climits>
#include <utility>
#include <numeric>
#include <cassert>

#endif

3. 验证

编译时使用 Homebrew 安装的 g++,例如:

bash 复制代码
/opt/homebrew/bin/g++-14 -o test test.cpp
相关推荐
TPBoreas1 小时前
Jenkins 改完端口号启动不起来了
java·开发语言
TE-茶叶蛋1 小时前
Vuerouter 的底层实现原理
开发语言·javascript·ecmascript
云闲不收2 小时前
设计模式原则
开发语言
秋名RG2 小时前
深入解析建造者模式(Builder Pattern)——以Java实现复杂对象构建的艺术
java·开发语言·建造者模式
技术求索者2 小时前
c++学习
开发语言·c++·学习
山猪打不过家猪3 小时前
(二)毛子整洁架构(CQRS/Dapper/领域事件处理器/垂直切片)
开发语言·.net
@PHARAOH3 小时前
HOW - 在 Mac 上的 Chrome 浏览器中调试 Windows 场景下的前端页面
前端·chrome·macos
方博士AI机器人5 小时前
Python 3.x 内置装饰器 (4) - @dataclass
开发语言·python
weixin_376934635 小时前
JDK Version Manager (JVMS)
java·开发语言
Logintern095 小时前
【每天学习一点点】使用Python的pathlib模块分割文件路径
开发语言·python·学习