@peccul is peccu

(love peccu '(emacs lisp cat outdoor bicycle mac linux coffee))

= Mac OS X Mountain LionでRのrglパッケージをインストールする(Rでglを使う)

[2012-08-31 13:37:14]

Mac Portsで入れたRでplot3d使おうとしてrglパッケージをインストールしたらエラーがでた.

こんなエラー

> install.packages("rgl")
Installing package(s) into ‘/Users/peccu/R/x86_64-apple-darwin12.0.0-library/2.15’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
Loading Tcl/Tk interface ... done
trying URL 'http://essrc.hyogo-u.ac.jp/cran/src/contrib/rgl_0.92.892.tar.gz'
Content type 'application/x-gzip' length 1713881 bytes (1.6 Mb)
opened URL
==================================================
downloaded 1.6 Mb

* installing *source* package ‘rgl’ ...
** package ‘rgl’ successfully unpacked and MD5 sums checked
checking for gcc... /opt/local/bin/gcc-mp-4.5 -std=gnu99
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether /opt/local/bin/gcc-mp-4.5 -std=gnu99 accepts -g... yes
checking for /opt/local/bin/gcc-mp-4.5 -std=gnu99 option to accept ISO C89... none needed
checking how to run the C preprocessor... /opt/local/bin/gcc-mp-4.5 -std=gnu99 -E
checking for gcc... (cached) /opt/local/bin/gcc-mp-4.5 -std=gnu99
checking whether we are using the GNU C compiler... (cached) yes
checking whether /opt/local/bin/gcc-mp-4.5 -std=gnu99 accepts -g... (cached) yes
checking for /opt/local/bin/gcc-mp-4.5 -std=gnu99 option to accept ISO C89... (cached) none needed
checking for libpng-config... yes
configure: using libpng-config
configure: using libpng dynamic linkage
checking for X... libraries , headers 
checking for glEnd in -lGL... no
configure: error: missing required library GL
ERROR: configuration failed for package ‘rgl’
* removing ‘/Users/peccu/R/x86_64-apple-darwin12.0.0-library/2.15/rgl’

The downloaded source packages are in
	‘/private/var/folders/9c/34q50wxx2ds0fr0sl99qf3d00000gn/T/RtmpDt5YNr/downloaded_packages’
Warning message:
In install.packages("rgl") :
  installation of package ‘rgl’ had non-zero exit status

GLが見つかってないようですね.

portsでのRのインストールオプションでopenglを指定できるかと思ったけど,どうもわからんかったので,openglのパスを通すことにしました.

Xcodeのインストールが必要だと思います.

glの場所を探す

% locate GL/gl.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/X11/include/GL/gl.h
% locate libglut
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/X11/lib/libglut.3.7.dylib
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/X11/lib/libglut.3.dylib
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/X11/lib/libglut.dylib
/usr/X11/lib/libglut.3.dylib

パスを指定しながらパッケージをインストール

Installing rgl in R under OS X Lion | drop.bit ここをみてたらMacPortsでfreeglutをインストールすればいいみたいですが,Xcodeに入ってるのでそっちを指定することにしました.

install.packages("rgl", configure.args="--disable-cocoa --with-gl-includes=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/X11/include --with-gl-libs=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/usr/X11/lib --with-x")

これでうまくいった.
configureオプションの --disable-cocoa と --with-xが必要なのかは確認してません.