Help us understand the problem. What is going on with this article?

macOS 10.15 Catalinaで、"fatal error: 'stdio.h' file not found"が出てしまう!

初めてRailsとやらの環境構築をしていた際、gem install pgなどすると以下のようなエラーが出ていて困り果てていました。

/Users/Rascal/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-18/2.6.0-static/pg-1.1.4/mkmf.log
find_executable: checking for pg_config... -------------------- yes

--------------------

"clang -o conftest -I/Users/Rascal/.rbenv/versions/2.6.4/include/ruby-2.6.0/x86_64-darwin18 -I/Users/Rascal/.rbenv/versions/2.6.4/include/ruby-2.6.0/ruby/backward -I/Users/Rascal/.rbenv/versions/2.6.4/include/ruby-2.6.0 -I. -I/usr/local/Cellar/postgresql/11.5_1/include -I/Users/Rascal/.rbenv/versions/2.6.4/include  -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -O3 -ggdb3 -Wall -Wextra -Wdeclaration-after-statement -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens  -pipe conftest.c  -L. -L/Users/Rascal/.rbenv/versions/2.6.4/lib -L/usr/local/lib -L. -L/Users/Rascal/.rbenv/versions/2.6.4/lib  -fstack-protector-strong -L/usr/local/opt/openssl/lib -L/usr/local/lib -L/usr/local/Cellar/llvm/8.0.1/lib/clang/8.0.1/lib     -lruby.2.6-static -framework Security -framework Foundation -lpthread -lgmp -ldl -lobjc   "
In file included from conftest.c:1:
In file included from /Users/Rascal/.rbenv/versions/2.6.4/include/ruby-2.6.0/ruby.h:33:
In file included from /Users/Rascal/.rbenv/versions/2.6.4/include/ruby-2.6.0/ruby/ruby.h:29:
In file included from /Users/Rascal/.rbenv/versions/2.6.4/include/ruby-2.6.0/ruby/defines.h:123:
/Library/Developer/CommandLineTools/usr/include/c++/v1/stdio.h:108:15: fatal error: 'stdio.h' file not found
#include_next <stdio.h>
              ^~~~~~~~~
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

/Users/Rascal/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-18/2.6.0-static/pg-1.1.4/mkmf.log (END)

stdio.hがないですと…?

Mojave(10.14)のときは、open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkgで何とかなっていたのですが今回からそのようなパッケージもなく、以下のパスを参照するようにしても上手く行きませんでした。
export CPATH=/Library/Developer/CommandLineTools/usr/include/c++/v1

結論としては、以下を~/.bash_profileなり~/.bashrcに追記することで問題は解消されました。
export SDKROOT="$(xcrun --sdk macosx --show-sdk-path)"

この問題にぶつかるまでは、Dockerを使っての環境構築をしていたので自身のマシンで苦労するとは思いませんでした。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away