LoginSignup
0
0

More than 3 years have passed since last update.

stdlib.h が見つからない on Mac OSX10.5

Posted at

stdlib.h が見つからない on Mac OSX10.5

つまらないインストール作業に時間を割いてしまったので、Tipsを共有します。Rのパッケージをインストールする際に、stdlib.hを参照できないエラーが起こる。しかし、このエラーは10.4の時にすぐに解決したはずと思っていましたが、検索すると古い情報が出てきて、新しいMacを利用する人はまたこの穴に落ちる可能性があると思いました。以下では、AnnotationHubというライブラリをインストールする際に必要なインストールステップのログになりますが、このライブラリに限ったことではありません。

  • 環境: R version 4.0.2, OSX 10.5
if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")

BiocManager::install("AnnotationHub")

--中略--
URL 'https://cran.rstudio.com/src/contrib/xfun_0.22.tar.gz' を試しています 
Content type 'application/x-gzip' length 105388 bytes (102 KB)
==================================================
downloaded 102 KB

* installing *source* package ‘xfun’ ...
**  パッケージ ‘xfun’ の解凍および MD5 サムの検証に成功しました 
** using staged installation
** libs
/usr/local/opt/llvm/bin/clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/usr/local/include   -fPIC  -Wall -g -O2  -c base64.c -o base64.o
base64.c:1:10: fatal error: 'stdlib.h' file not found
#include <stdlib.h>
         ^~~~~~~~~~
1 error generated.
make: *** [base64.o] Error 1
ERROR: compilation failed for package ‘xfun’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/xfun’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/xfun’

The downloaded source packages are in
    ‘/private/var/folders/x6/8wv_jnc97_96rqvqsnfytgp00000gn/T/RtmpIcrQHv/downloaded_packages’
 警告メッセージ: 
 install.packages(update[instlib == l, "Package"], l, repos = repos,  で: 
  installation of package ‘xfun’ had non-zero exit status

clangが/user/local/includeの中にあるはずのstdlib.hが見つからないと言っています。古い解決法(<10.4)では、OSXのdevtoolsのSDKs header パッケージをインストールする方法です。

xcode-select --install

もしくは、直接ヘッダのパッケージを展開します。

open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

しかしながら、私の環境の10.5ではこのファイルパスは正しくなく、フォルダの中身をみるとすでにこのpackageを展開している環境になっています。そこで、stdlib.hに直接パスを通してやることにしました。

R console上で

Sys.setenv("CPATH"="/usr/local/include:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include")

その後再度インストールを再実行 (成功)

BiocManager::install("AnnotationHub")

-- 中略 -- 
193 warnings generated.
clang++ -mmacosx-version-min=10.13 -std=gnu++11 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o xfun.so base64.o init.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: warning: object file (base64.o) was built for newer macOS version (10.15) than being linked (10.13)
ld: warning: object file (init.o) was built for newer macOS version (10.15) than being linked (10.13)
installing to /Library/Frameworks/R.framework/Versions/4.0/Resources/library/00LOCK-xfun/00new/xfun/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (xfun)

The downloaded source packages are in
    ‘/private/var/folders/x6/8wv_jnc97_96rqvqsnfytgp00000gn/T/RtmpgcCKBM/downloaded_packages’
0
0
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
0
0