2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

macOSでコンパイルエラー: unknown typeとかno memberとかが大量に出たらやること

Last updated at Posted at 2019-04-30

macOSでのコンパイルにおいて、ユーザー定義の型識別子に関して大量のエラーが発生した場合の、対処方法を記載しておきます。英文サイトに事象と解決策はいくつか掲載されているのですが、どれもはっきりとした書き方はされていません。私がハマって解決した例として参考にしてください。

1. エラーの例

明示的にmakeやcmakeでコンパイルした場合、brew installでパッケージが見つからなくてソースコンパイルが行われた場合などに、以下のエラーがでます。

/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdint:158:8: error: no member named 'uint8_t' in the global namespace using::uint8_t;

(同様なものが大量に出ます)
(error: unknown type name 'uint8_t' とかの場合もあります)

fatal error: too many errors emitted, stopping now [-ferror-limit=]

2. 原因

macOSをアップグレードした際に、古いヘッダファイルが残存してしまうためのようてす。私の場合は、High SierraからMojaveにアップグレードしていました。

3. 対処

/usr/local/includeを強制的に切り替えます。この中はヘッダファイルだけしかありませんので、macOSの動作そのものには影響を与えませんので、ご安心ください。

$ sudo mv /usr/local/include /usr/local/include.org

削除する、という荒っぽい解決策もいくつかみられましたが、戻せるようにリネームしておきます。

たたし、これだけだと、コンパイルは通りません。コンパイル時に/usr/local/include/なんとか、が無いと怒られます。homebrewを最初からインストールしなおしして、さらにコンパイル時に無いと怒られる「なんとか」に関係するパッケージ(しかしbrewではあると言われる)について、brew uninstallして、brew installしなおすことを繰り返します。これによって、新しい /usr/local/inbclude (中身はシンボリックリンクだけですが)が作られ、コンパイル可能になります。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?