[Rcpp-devel] Successful install of rcppbugs on Mac OS X 10.7
Steve Lianoglou
mailinglist.honeypot at gmail.com
Fri May 25 18:10:49 CEST 2012
Hi,
Thanks for the detailed instructions on getting gcc-4.6 cooking on the mac.
One question though -- I thought it was considered a "bad idea" to
have R (and its libraries) compiled w/ different compilers.
You now have base R which was compiled w/ apple's gcc (4.2) as well as
a slew of other "C-inside R packages," but you now also have rcppbugs
(and maybe other ones you compile in the future) being built w/
gcc-4.6
Isn't this a bad idea?
-steve
On Fri, May 25, 2012 at 1:34 AM, Nick Matzke <matzke at berkeley.edu> wrote:
> Hi all,
>
> Thanks for your help (Whit especially) on various things. After a fair bit
> of effort I got rccpbugs installed on my Mac 10.7 in R.app. Here's my
> setup:
>
>> sessionInfo()
> R version 2.14.1 (2011-12-22)
> Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
>
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
> [1] stats grDevices utils datasets graphics methods base
>
> other attached packages:
> [1] rcppbugs_0.1.0 RcppArmadillo_0.3.0.2 Rcpp_0.9.10
> inline_0.3.8
>
> loaded via a namespace (and not attached):
> [1] compiler_2.14.1 tools_2.14.1
>
>
>
>
>
> The basic steps:
>
> 1. Install dependencies
> install.packages("Rcpp")
> install.packages("inline")
>
> 2. (I updated Xcode to 3.2 and installed the Command Line Tools, I doubt the
> details of this matter though.)
>
> 3. The default compiler on Mac OS X 10.7 is gcc4.2. However, rcppbugs needs
> gcc4.6. I got gcc4.6 to install by following the directions here:
>
> http://solarianprogrammer.com/2011/12/01/compiling-gcc-4-6-2-on-mac-osx-lion/
>
> If you want to try gcc4.7, the instructions are here, but Whit recommends
> against it for now:
>
> http://solarianprogrammer.com/2012/02/20/living-on-the-edge-building-gcc-4-7-on-mac-osx-lion/
>
> In my case, I installed gcc46 and the 3 dependencies in (root)/my_gcc rather
> than $HOME/my_gcc. After installing the dependencies, I configured and
> maked the gcc46 install as follows:
>
> In Terminal (not R):
> ========================
> cd /Users/nickm/Downloads/z_installed_good/gcc47/
> 502 ls
> 503 gunzip -c mpc-0.9.tar.gz | tar xopf -
> 504 gunzip -c mpfr-3.1.0.tar.gz | tar xopf -
> 505 gunzip -c gmp-5.0.5.tar.gz | tar xopf -
> 506 gunzip -c gmp-5.0.5.tar.bz2 | tar xopf -
> 507 tar jxf gmp-5.0.5.tar.bz2
> 508 ls
> 509 cd gmp*
> 510 mkdir build
> 511 cd build
> 514 ../configure --prefix=/my_gcc
> 515 make
> 516 make install
> 517 cd ..
> 518 cd ..
> 519 cd mpfr*
> 520 mkdir build
> 521 cd build
> 522 ../configure --prefix=/my_gcc --with-gmp=/my_gcc
> 523 pwd
> 524 make
> 525 make install
> 526 cd ..
> 527 cd ..
> 528 cd mpc*
> 529 mkdir build
> 530 cd build
> 532 ../configure --prefix=/my_gcc --with-gmp=/my_gcc --with-mpfr=/my_gcc
> 533 make
> 534 make install
> 535 cd ..
> 536 cd ..
> 537 ls
> 548 cd /Users/nickm/Downloads/z_installed_good/gcc46/
> 549 ls
> 550 gunzip -c gcc-4.6.3.tar.gz | tar xopf -
> 560 cd gcc*
> 561 ls
> 562 mkdir build
> 563 cd build
> 564 ls
> 565 ../configure --prefix=/my_gcc --enable-checking-release
> --with-gmp=/my_gcc --with-mpfr=/my_gcc --enable-languages=c,c++,fortran
> --program-suffix=46
> 566 make -j 4
> 567 ls
> 568 cd bin
> 569 make install
> 570 history
> ========================
>
>
>
> 4. Now we have gcc 4.6.3 installed as /my_gcc/gcc46, and also g++46 (R uses
> g++ by default), but R CMD INSTALL doesn't know where to find it. Solution:
>
> 4a. First we make gcc46 the default gcc:
>
> # g++
>
> # Change symbolic linkage:
> cd /usr/bin
> rm g++; ln -s /my_gcc/bin/g++46 /usr/bin/g++
>
>
> (To turn it back later, we can do this)
>
> # Change it back
> cd /usr/bin
> rm g++; ln -s /usr/bin/llvm-g++-4.2 /usr/bin/g++
>
>
>
> 4b. Now when we run R CMD INSTALL, it uses the correct g++, but for whatever
> reason, with gcc 4.6 the "-arch x86_64" flag is not recognized, so this
> throws an error when you attempt to install.
>
> The default settings for the command-line R CMD INSTALL (and R CMD SHLIB)
> commands are stored in something like $R_HOME/etc/Makeconf. You can figure
> it out exactly with R.home:
>
> # Return the R Home Directory
> # http://stat.ethz.ch/R-manual/R-patched/library/base/html/Rhome.html
>
> In R:
>
> R.home(component="home")
>
> # "/Library/Frameworks/R.framework/Resources"
> #
> # Find the Makeconf file (default Make settings)
> # cd /Library/Frameworks/R.framework/Resources/etc/x86_64/
> #
>
> In my case, the Makeconf file was at:
>
> /Library/Frameworks/R.framework/Resources/etc/x86_64/Makeconf
>
>
>
> 4c. The variables specifying the compiler are:
> CXX
> SHLIB_CXXLD
>
> They can be changed from their defaults by editing Makeconf:
>
> /Library/Frameworks/R.framework/Resources/etc/x86_64/Makeconf
>
> Or, more easily/properly by creating a Makevars file in $HOME/.R/Makevars
>
> # The Makevars file should be stored at:
> # $HOME/.R/Makevars
>
> I did the latter.
>
>
> 5. The Makevars file:
>
> $Home/.R/Makevars
> /Users/nickm/.R/Makevars
> ==============================
> # THIS IS THE MANUALLY-CREATED Makevars file WHICH LETS YOU CUSTOMIZE
> # R CMD INSTALL and R CMD SHLIB compiler flags more easily than you
> # would by modifying the Makeconf default file directly.
> #
> # (On this machine, Makeconf default file is at:
> # /Library/Frameworks/R.framework/Resources/etc/x86_64/Makeconf
> # )
> #
> # The Makevars file should be stored at:
> # $HOME/.R/Makevars
> #
> #
> # default for R 2.14 on Mac OS X 10.7 is to use gcc --> gcc4.2
> # but we want to use gcc4.6, which doesn't use the -arch (architecture) tags
> #
> # So, edit that environment variable for R CMD INSTALL and R CMD SHLIB
> #
> # CXX - the compiler for each code file
> #CXX=g++ -arch x86_64
> CXX=g++ -std=c++0x
>
> # SHLIB_CXXLD - maybe this is the linker? - YEP
> #SHLIB_CXXLD = g++ -arch x86_64
> SHLIB_CXXLD = g++ -std=c++0x
> ==============================
>
>
>
> 6. Now we are ready for rcppbugs. Download and unzip the source from here:
>
> http://cran.r-project.org/web/packages/rcppbugs/index.html
>
>
> 7. In R:
>
> ===================
> # Install from source, after changing compiler to g++46 and modifying
> Makevars:
> packagepath =
> "/Users/nickm/Desktop/__projects/__BayArea/_detection_probability/_RcppBUGS/rcppbugs"
>
> libpath = "/Library/Frameworks/R.framework/Resources/library/"
>
> install.packages(c(packagepath), libpath, NULL, type='source',
> INSTALL_opts=c("--no-multiarch"))
>
> cmd = paste("R CMD INSTALL --preclean --no-multiarch --library=", libpath, "
> ", packagepath, sep="")
>
> system(cmd)
> ===================
>
>
> The --no-multiarch flag was needed because otherwise R on Mac OS X attempts
> to also compile for PPC or i386 architecture or something, and I didn't want
> to figure that out.
>
>
>
> 8. Test code:
>
> ====================================
> ?run.model
>
> # Example code from run.model
>
> NR <- 1e2L
> NC <- 2L
> y <- matrix(rnorm(NR,1) + 10,nr=NR,nc=1L)
> X <- matrix(nr=NR,nc=NC)
> X[,1] <- 1
> X[,2] <- y + rnorm(NR)/2 - 10
>
> ## RCppBugs Model
> b <- mcmc.normal(rnorm(NC),mu=0,tau=0.0001)
> tau.y <- mcmc.gamma(sd(as.vector(y)),alpha=0.1,beta=0.1)
> y.hat <- linear(X,b)
> y.lik <- mcmc.normal(y,mu=y.hat,tau=tau.y,observed=TRUE)
> m <- create.model(b, tau.y, y.hat, y.lik)
>
>
> runtime <- system.time(ans <- run.model(m, iterations=1e2L, burn=1e2L,
> adapt=1e3L, thin=10L))
> print(get.ar(ans))
>
> print(apply(ans[["b"]],2,mean))
> ====================================
>
> Done!
>
> Nick
>
>
>
> PS:
>
> STUFF THAT DIDN'T WORK, BUT WHICH MIGHT BE HANDY TO GOOGLE FOR OTHERS WHO
> HIT MY ERROR MESSAGES:
>
>
>
> ERRORS TRYING TO COMPILE cppbugs code (the precursor of rcppbugs) with the
> wrong compilers etc.; many of these are the product of attempting to compile
> with g++4.2, although I never got g++4.6 or 4.7 to work either, could be the
> -std flag was wrong or something. I got similar error messages with
> rcppbugs early on before I switched compilers.
>
> ============
> (very long, see next message)
> ============
>
>
>
> LEFT OUT THE --no-multiarch FLAG
> =========================
> install.packages(c(packagepath),
> "/Library/Frameworks/R.framework/Resources/library/", NULL, type='source')
> * installing *source* package ‘rcppbugs’ ...
> files src/Makevars, src/Makevars.win,
> src/cppbugs/cppbugs/mcmc.bernoulli.hpp, src/cppbugs/cppbugs/mcmc.beta.hpp,
> src/cppbugs/cppbugs/mcmc.binomial.hpp, src/cppbugs/cppbugs/mcmc.gamma.hpp,
> src/cppbugs/cppbugs/mcmc.model.hpp,
> src/cppbugs/cppbugs/mcmc.multivariate.normal.hpp,
> src/cppbugs/cppbugs/mcmc.normal.hpp,
> src/cppbugs/cppbugs/mcmc.stochastic.hpp,
> src/cppbugs/cppbugs/mcmc.uniform.hpp, src/r.mcmc.model.h have the wrong MD5
> checksums
> ** libs
> *** arch - i386
> g++ -std=c++0x -I/Library/Frameworks/R.framework/Resources/include
> -I/Library/Frameworks/R.framework/Resources/include/i386
> -I/usr/local/include
> -I"/Library/Frameworks/R.framework/Versions/2.14/Resources/library/Rcpp/include"
> -I"/Library/Frameworks/R.framework/Versions/2.14/Resources/library/RcppArmadillo/include"
> -I/opt/local/include -I./cppbugs -fPIC -g -O2 -c interface.cpp -o
> interface.o
> g++ -std=c++0x -I/Library/Frameworks/R.framework/Resources/include
> -I/Library/Frameworks/R.framework/Resources/include/i386
> -I/usr/local/include
> -I"/Library/Frameworks/R.framework/Versions/2.14/Resources/library/Rcpp/include"
> -I"/Library/Frameworks/R.framework/Versions/2.14/Resources/library/RcppArmadillo/include"
> -I/opt/local/include -I./cppbugs -fPIC -g -O2 -c raw.address.cpp -o
> raw.address.o
> g++ -arch i386 -dynamiclib -Wl,-headerpad_max_install_names -undefined
> dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -o
> rcppbugs.so helpers.o interface.o raw.address.o
> /Library/Frameworks/R.framework/Versions/2.14/Resources/library/Rcpp/lib/i386/libRcpp.a
> -L/Library/Frameworks/R.framework/Resources/lib/i386 -lRlapack
> -L/Library/Frameworks/R.framework/Resources/lib/i386 -lRblas -lgfortran
> -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework
> -Wl,CoreFoundation
> g++: error: i386: No such file or directory
> g++: error: unrecognized option ‘-arch’
> make: *** [rcppbugs.so] Error 1
> ERROR: compilation failed for package ‘rcppbugs’
> * removing
> ‘/Library/Frameworks/R.framework/Versions/2.14/Resources/library/rcppbugs’
> Warning message:
> In install.packages(c(packagepath),
> "/Library/Frameworks/R.framework/Resources/library/", :
> installation of package
> ‘/Users/nickm/Desktop/__projects/__BayArea/_detection_probability/_RcppBUGS/rcppbugs’
> had non-zero exit status
> =========================
>
>
>
> CXX CHANGED, BUT NOT SHLIB_CXXLD:
> ====================
> system(cmd)
> * installing *source* package ‘rcppbugs’ ...
> files src/Makevars, src/Makevars.win,
> src/cppbugs/cppbugs/mcmc.bernoulli.hpp, src/cppbugs/cppbugs/mcmc.beta.hpp,
> src/cppbugs/cppbugs/mcmc.binomial.hpp, src/cppbugs/cppbugs/mcmc.gamma.hpp,
> src/cppbugs/cppbugs/mcmc.model.hpp,
> src/cppbugs/cppbugs/mcmc.multivariate.normal.hpp,
> src/cppbugs/cppbugs/mcmc.normal.hpp,
> src/cppbugs/cppbugs/mcmc.stochastic.hpp,
> src/cppbugs/cppbugs/mcmc.uniform.hpp, src/r.mcmc.model.h have the wrong MD5
> checksums
> ** libs
> *** arch - x86_64
> g++ -std=c++0x -I/Library/Frameworks/R.framework/Resources/include
> -I/Library/Frameworks/R.framework/Resources/include/x86_64
> -I/usr/local/include
> -I"/Library/Frameworks/R.framework/Versions/2.14/Resources/library/Rcpp/include"
> -I"/Library/Frameworks/R.framework/Versions/2.14/Resources/library/RcppArmadillo/include"
> -I/opt/local/include -I./cppbugs -fPIC -g -O2 -c helpers.cpp -o helpers.o
> g++ -std=c++0x -I/Library/Frameworks/R.framework/Resources/include
> -I/Library/Frameworks/R.framework/Resources/include/x86_64
> -I/usr/local/include
> -I"/Library/Frameworks/R.framework/Versions/2.14/Resources/library/Rcpp/include"
> -I"/Library/Frameworks/R.framework/Versions/2.14/Resources/library/RcppArmadillo/include"
> -I/opt/local/include -I./cppbugs -fPIC -g -O2 -c interface.cpp -o
> interface.o
> g++ -std=c++0x -I/Library/Frameworks/R.framework/Resources/include
> -I/Library/Frameworks/R.framework/Resources/include/x86_64
> -I/usr/local/include
> -I"/Library/Frameworks/R.framework/Versions/2.14/Resources/library/Rcpp/include"
> -I"/Library/Frameworks/R.framework/Versions/2.14/Resources/library/RcppArmadillo/include"
> -I/opt/local/include -I./cppbugs -fPIC -g -O2 -c raw.address.cpp -o
> raw.address.o
> g++ -arch x86_64 -dynamiclib -Wl,-headerpad_max_install_names -undefined
> dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -o
> rcppbugs.so helpers.o interface.o raw.address.o
> /Library/Frameworks/R.framework/Versions/2.14/Resources/library/Rcpp/lib/x86_64/libRcpp.a
> -L/Library/Frameworks/R.framework/Resources/lib/x86_64 -lRlapack
> -L/Library/Frameworks/R.framework/Resources/lib/x86_64 -lRblas -lgfortran
> -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework
> -Wl,CoreFoundation
> g++: error: x86_64: No such file or directory
> g++: error: unrecognized option ‘-arch’
> make: *** [rcppbugs.so] Error 1
> ERROR: compilation failed for package ‘rcppbugs’
> * removing
> ‘/Library/Frameworks/R.framework/Versions/2.14/Resources/library/rcppbugs’
> ====================
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> --
> ====================================================
> Nicholas J. Matzke
> Ph.D. Candidate, Graduate Student Researcher
>
> Huelsenbeck Lab
> Center for Theoretical Evolutionary Genomics
> 4151 VLSB (Valley Life Sciences Building)
> Department of Integrative Biology
> University of California, Berkeley
>
> Graduate Student Instructor, IB200B
> Principles of Phylogenetics: Ecology and Evolution
> http://ib.berkeley.edu/courses/ib200b/
> http://phylo.wikidot.com/
>
>
> Lab websites:
> http://ib.berkeley.edu/people/lab_detail.php?lab=54
> http://fisher.berkeley.edu/cteg/hlab.html
> Dept. personal page:
> http://ib.berkeley.edu/people/students/person_detail.php?person=370
> Lab personal page: http://fisher.berkeley.edu/cteg/members/matzke.html
> Lab phone: 510-643-6299
> Dept. fax: 510-643-6264
>
> Cell phone: 510-301-0179
> Email: matzke at berkeley.edu
>
> Mailing address:
> Department of Integrative Biology
> 1005 Valley Life Sciences Building #3140
> Berkeley, CA 94720-3140
>
> -----------------------------------------------------
> "[W]hen people thought the earth was flat, they were wrong. When people
> thought the earth was spherical, they were wrong. But if you think that
> thinking the earth is spherical is just as wrong as thinking the earth is
> flat, then your view is wronger than both of them put together."
>
> Isaac Asimov (1989). "The Relativity of Wrong." The Skeptical Inquirer,
> 14(1), 35-44. Fall 1989.
> http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm
> ====================================================
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
--
Steve Lianoglou
Graduate Student: Computational Systems Biology
| Memorial Sloan-Kettering Cancer Center
| Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact
More information about the Rcpp-devel
mailing list