質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
g++

g++はGNUコンパイラコレクション(gcc)のC++コンパイラーです。

GCC

GCCはGNU Compiler Collectionの略です。LinuxのC言語コンパイラのデファクトスタンダードであり、数多くの他言語やプラットフォームサポートもします。

MacOS(OSX)

MacOSとは、Appleの開発していたGUI(グラフィカルユーザーインターフェース)を採用したオペレーションシステム(OS)です。Macintoshと共に、市場に出てGUIの普及に大きく貢献しました。

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

Q&A

解決済

1回答

1980閲覧

bits/stdc++のコンパイルでエラーが出る

kyokio

総合スコア560

g++

g++はGNUコンパイラコレクション(gcc)のC++コンパイラーです。

GCC

GCCはGNU Compiler Collectionの略です。LinuxのC言語コンパイラのデファクトスタンダードであり、数多くの他言語やプラットフォームサポートもします。

MacOS(OSX)

MacOSとは、Appleの開発していたGUI(グラフィカルユーザーインターフェース)を採用したオペレーションシステム(OS)です。Macintoshと共に、市場に出てGUIの普及に大きく貢献しました。

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

1グッド

1クリップ

投稿2021/12/12 13:38

bits/stdc++のコンパイルのエラーを解消したい

Macをアップデートして、Montereyにするとg++でコンパイルすると下記の警告が出るようになりました。

terminal

1ld: warning: dylib (/usr/local/Cellar/gcc/11.2.0/lib/gcc/11/libstdc++.dylib) was built for newer macOS version (11.3) than being linked (11.0)

こちらのサイトを参考にgccをreinstallしたらコンパイルできなくなりました。
以下エラー内容です。

発生している問題・エラーメッセージ

progA

1#include<bits/stdc++.h> 2using namespace std; 3 4int main(){ 5 6 double n; 7 cin >> n; 8 cout << n/100 << endl; 9} 10 11

上のprogA.cppg++ progA.cppでコンパイルすると下記のエラーが出ます。

terminal

1In file included from /usr/local/Cellar/gcc/11.2.0_3/include/c++/11/x86_64-apple-darwin21/bits/stdc++.h:34, 2 from progD.cpp:1: 3/usr/local/Cellar/gcc/11.2.0_3/include/c++/11/cassert:44:10: fatal error: assert.h: No such file or directory 4 44 | #include <assert.h> 5 | ^~~~~~~~~~ 6compilation terminated.

試したこと

①--sysrootオプションでコンパイル

こちらのサイトを参考に、
g++ --sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/ progA.cppを実行すると正常にコンパルできました。
エイリアスを使用してこのままにするのもあまり気分が良くないのでg++だけでコンパイルできるようにしたいです。

②-vオプションでコンパイル

-vオプションでコンパイルすると、色々出てきました。
その中で下記の部分にbits/stdc++.hが含まれていないのが原因なのではないかと考えています。

#include <...> search starts here: /usr/local/Cellar/gcc/11.2.0_3/lib/gcc/11/gcc/x86_64-apple-darwin21/11/../../../../../../include/c++/11 /usr/local/Cellar/gcc/11.2.0_3/lib/gcc/11/gcc/x86_64-apple-darwin21/11/../../../../../../include/c++/11/x86_64-apple-darwin21 /usr/local/Cellar/gcc/11.2.0_3/lib/gcc/11/gcc/x86_64-apple-darwin21/11/../../../../../../include/c++/11/backward /usr/local/Cellar/gcc/11.2.0_3/lib/gcc/11/gcc/x86_64-apple-darwin21/11/include /usr/local/Cellar/gcc/11.2.0_3/lib/gcc/11/gcc/x86_64-apple-darwin21/11/include-fixed End of search list.
Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/11.2.0_3/libexec/gcc/x86_64-apple-darwin21/11/lto-wrapper Target: x86_64-apple-darwin21 Configured with: ../configure --prefix=/usr/local/Cellar/gcc/11.2.0_3 --libdir=/usr/local/Cellar/gcc/11.2.0_3/lib/gcc/11 --disable-nls --enable-checking=release --with-gcc-major-version-only --enable-languages=c,c++,objc,obj-c++,fortran,d --program-suffix=-11 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-zstd=/usr/local/opt/zstd --with-pkgversion='Homebrew GCC 11.2.0_3' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --enable-libphobos --build=x86_64-apple-darwin21 --with-system-zlib --disable-multilib --without-build-config --with-native-system-header-dir=/usr/include --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.2.0 (Homebrew GCC 11.2.0_3) COLLECT_GCC_OPTIONS='-v' '-mmacosx-version-min=12.0.0' '-asm_macosx_version_min=12.0' '-shared-libgcc' '-mtune=core2' '-dumpdir' 'a-' /usr/local/Cellar/gcc/11.2.0_3/libexec/gcc/x86_64-apple-darwin21/11/cc1plus -quiet -v -D__DYNAMIC__ progA.cpp -fPIC -quiet -dumpdir a- -dumpbase progA.cpp -dumpbase-ext .cpp -mmacosx-version-min=12.0.0 -mtune=core2 -version -o /var/folders/_l/j5clvymx4kdf0j3_brzzh3pw0000gn/T//ccLblSz9.s GNU C++17 (Homebrew GCC 11.2.0_3) version 11.2.0 (x86_64-apple-darwin21) compiled by GNU C version 11.2.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version isl-0.24-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/local/include" ignoring nonexistent directory "/usr/local/Cellar/gcc/11.2.0_3/lib/gcc/11/gcc/x86_64-apple-darwin21/11/../../../../../../x86_64-apple-darwin21/include" ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include" ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/System/Library/Frameworks" ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/Library/Frameworks" #include "..." search starts here: #include <...> search starts here: /usr/local/Cellar/gcc/11.2.0_3/lib/gcc/11/gcc/x86_64-apple-darwin21/11/../../../../../../include/c++/11 /usr/local/Cellar/gcc/11.2.0_3/lib/gcc/11/gcc/x86_64-apple-darwin21/11/../../../../../../include/c++/11/x86_64-apple-darwin21 /usr/local/Cellar/gcc/11.2.0_3/lib/gcc/11/gcc/x86_64-apple-darwin21/11/../../../../../../include/c++/11/backward /usr/local/Cellar/gcc/11.2.0_3/lib/gcc/11/gcc/x86_64-apple-darwin21/11/include /usr/local/Cellar/gcc/11.2.0_3/lib/gcc/11/gcc/x86_64-apple-darwin21/11/include-fixed End of search list. GNU C++17 (Homebrew GCC 11.2.0_3) version 11.2.0 (x86_64-apple-darwin21) compiled by GNU C version 11.2.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version isl-0.24-GMP GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: d53d5a666dbc2745db3c8ee0587d076d In file included from /usr/local/Cellar/gcc/11.2.0_3/include/c++/11/x86_64-apple-darwin21/bits/stdc++.h:34, from progA.cpp:1: /usr/local/Cellar/gcc/11.2.0_3/include/c++/11/cassert:44:10: fatal error: assert.h: No such file or directory 44 | #include <assert.h> | ^~~~~~~~~~ compilation terminated.

③asser.hを探す

sudo find / -name assert.hを実行して存在するか確認しました。
たくさん見つかりました。

/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/assert.h /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/kern/assert.h /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/IOKit/assert.h /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/assert.h /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/kern/assert.h /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/IOKit/assert.h /Library/InstallerSandboxes/.PKInstallSandboxManager/B4774526-2320-4C2C-97EC-24D87379E41F.activeSandbox/Root/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include/assert.h --------省略-----------

参考サイト

[1]unknown warning showing up
[2]Macのgcc, g++をHomebrewを使って最新版にする
[3]MacでGCCを"正しく"環境構築しよう!
[4]stdc++.h
[5]CatalinaでC++のコンパイルができない
[6]Catalinaへのアップデート後 bits/stdc++.h が使えなくなった
[7]os のアップデートをして, atom で以下のエラーが出たのですが, 改善法を教えてください
[8]macOSでgccが入らない
[9]gcc コンパイルオプション備忘録

t_kwauchiya👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

アップデートしたら直りました

投稿2022/05/17 16:26

kyokio

総合スコア560

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問