r-lib / pkgbuild

Find tools needed to build R packages
https://pkgbuild.r-lib.org
Other
65 stars 33 forks source link

Configuration issue leads to bad interaction between RStudio IDE and pkgbuild #118

Closed jphill01 closed 2 years ago

jphill01 commented 3 years ago

After recently upgrading to macOS Big Sur 11.4, I'm having issues building and installing my R package from source, which relies on compiled code via both Rcpp and RcppAramadillo.

I've upgraded to R 4.1.0 and RStudio 1.4.1717. I have also updated to Xcode 12.5.1 (12E507).

Command line tools is installed, as well as functionality for OpenMP.

Each time I run pkgbuild::build() (or equivalently devtools::build() followed by devtools::install()), I am prompted to install additional build tools.

When I click "Yes", R gives the error

Error: Could not find tools necessary to compile a package
Call `pkgbuild::check_build_tools(debug = TRUE)` to diagnose the problem.

When I call pkgbuild::check_build_tools(debug = TRUE) nothing happens.

I followed instructions in this SO post:

https://stackoverflow.com/questions/65251887/clang-7-error-linker-command-failed-with-exit-code-1-for-macos-big-sur/65334247#65334247

but the issue is still unresolved.

Is this a legitimate bug? How should I go about resolving my issue?

Thanks!

jimhester commented 3 years ago

I think this is a bad interaction between RStudio's detection and your system.

Try not installing the build tools in RStudio, open a separate terminal window, install the build tools there and then open R in that same window and run pkgbuild::check_build_tools(debug = TRUE) and see if it works.

I use macOS Big Sur 11.4 myself and do not see this issue, so I am confident this is not a general problem with RStudio and pkgbuild but something specific to your current configuration.

Nonetheless I would like to help you resolve it if possible.

jphill01 commented 3 years ago

Hi Jim,

I'm unsure on how exactly to install the additional build tools from the terminal. Is there a specific block of commands that needs to be executed? Could you walk me through it?

Thanks.

Jarrett

jphill01 commented 3 years ago

After doing some reading online, it seems that macOS Big Sur and clang are not friends and it is advised to alter the Makevars file within the .R folder to enable gcc/g++.

I am working though this document

http://yiqingxu.org/public/BigSurError.pdf

Currently, my Makevars look like

# The following statements are required to use the clang4 binary
CC=/usr/local/clang4/bin/clang
CXX=/usr/local/clang4/bin/clang++
CXX1X=/usr/local/clang4/bin/clang++
CXX98=/usr/local/clang4/bin/clang++
CXX11=/usr/local/clang4/bin/clang++
CXX14=/usr/local/clang4/bin/clang++
CXX17=/usr/local/clang4/bin/clang++
LDFLAGS=-L/usr/local/clang4/lib
# End clang4 inclusion statements

I am thinking to change the above to rely on gcc/g++ instead.

Since you peraonally use Big Sur, what compiler do you rely upon (clang or gcc/g++)?

jimhester commented 3 years ago

The default apple compiler is clang, it works perfectly fine for R packages. If you have everything installed correctly you don't need anything in your personal or site makevars. Also just putting g++ or gcc in your Makevars does not use GCC, by default clang is what is called by g++ e.g.

> g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 12.0.5 (clang-1205.0.22.11)
Target: x86_64-apple-darwin20.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Are you / they using homebrew R? If so, uninstall it and install the cask, e.g.

brew install --cask r
jphill01 commented 3 years ago

No. I'm not using Homebrew R, but I do have Homebrew installed:

Jarretts-MacBook-Pro-3:~ jarrettphillips$ brew config
HOMEBREW_VERSION: 3.2.0
ORIGIN: https://github.com/Homebrew/brew
HEAD: 09f7bc27a99469cf947431df4754737dfbadb31d
Last commit: 2 weeks ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: b1c76d0f6e481ae009775f96f89c6cd1c635822d
Core tap last commit: 3 days ago
Core tap branch: master
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CASK_OPTS: []
HOMEBREW_DISPLAY: /private/tmp/com.apple.launchd.syQHtikHlQ/org.macosforge.xquartz:0
HOMEBREW_MAKE_JOBS: 4
Homebrew Ruby: 2.6.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: quad-core 64-bit broadwell
Clang: 12.0.5 build 1205
Git: 2.10.1 => /usr/local/bin/git
Curl: 7.64.1 => /usr/bin/curl

Not sure how else to proceed here, but I do appreciate the help.

UPDATE #1

I did manage to bypass the prompt to build additional tools in R with

options(buildtools.check = function(action) TRUE )

for debugging purposes. I now get a bunch of errors when calling

devtools::build()

on my package.

It's long, but here is what I get

installing source package ‘HACSim’ ... using staged installation libs clang++ -mmacosx-version-min=10.13 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I'/Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include' -I'/Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppArmadillo/include' -I/usr/local/include -fPIC -Wall -g -O2 -Wall -pedantic -fdiagnostics-color=always -c RcppExports.cpp -o RcppExports.o In file included from RcppExports.cpp:4: In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppArmadillo/include/RcppArmadillo.h:31: In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppArmadillo/include/RcppArmadilloForward.h:26: In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/RcppCommon.h:29: In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp/r/headers.h:67: In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp/platform/compiler.h:100: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:321:9: error: no member named 'signbit' in the global namespace using ::signbit; ~~^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:322:9: error: no member named 'fpclassify' in the global namespace using ::fpclassify; ~~^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:323:9: error: no member named 'isfinite' in the global namespace; did you mean 'finite'? using ::isfinite; ~~^ /usr/local/include/math.h:752:12: note: 'finite' declared here extern int finite(double) ^ In file included from RcppExports.cpp:4: In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppArmadillo/include/RcppArmadillo.h:31: In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppArmadillo/include/RcppArmadilloForward.h:26: In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/RcppCommon.h:29: In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp/r/headers.h:67: In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp/platform/compiler.h:100: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:324:9: error: no member named 'isinf' in the global namespace using ::isinf; ~~^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:325:9: error: no member named 'isnan' in the global namespace using ::isnan; ~~^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:326:9: error: no member named 'isnormal' in the global namespace using ::isnormal; ~~^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:327:9: error: no member named 'isgreater' in the global namespace using ::isgreater; ~~^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:328:9: error: no member named 'isgreaterequal' in the global namespace using ::isgreaterequal; ~~^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:329:9: error: no member named 'isless' in the global namespace using ::isless; ~~^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:330:9: error: no member named 'islessequal' in the global namespace using ::islessequal; ~~^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:331:9: error: no member named 'islessgreater' in the global namespace using ::islessgreater; ~~^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:332:9: error: no member named 'isunordered' in the global namespace using ::isunordered; ~~^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:333:9: error: no member named 'isunordered' in the global namespace using ::isunordered; ~~^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:339:9: error: no member named 'abs' in the global namespace; did you mean 'fabs'? using ::abs; ~~^ /usr/local/include/math.h:417:15: note: 'fabs' declared here extern double fabs(double); ^ In file included from RcppExports.cpp:4: In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppArmadillo/include/RcppArmadillo.h:31: In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppArmadillo/include/RcppArmadilloForward.h:26: In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/RcppCommon.h:29: In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp/r/headers.h:67: In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp/platform/compiler.h:100: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:644:26: error: no template named 'numeric_limits' bool _FloatBigger = (numeric_limits<_FloatT>::digits > numeric_limits<_IntT>::digits), ^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:644:60: error: no template named 'numeric_limits' bool _FloatBigger = (numeric_limits<_FloatT>::digits > numeric_limits<_IntT>::digits), ^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:645:18: error: no template named 'numeric_limits' int _Bits = (numeric_limits<_IntT>::digits - numeric_limits<_FloatT>::digits)> ^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:645:50: error: no template named 'numeric_limits' int _Bits = (numeric_limits<_IntT>::digits - numeric_limits<_FloatT>::digits)> ^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:650:17: error: no template named 'numeric_limits' static_assert(numeric_limits<_FloatT>::radix == 2, "FloatT has incorrect radix"); ^ fatal error: too many errors emitted, stopping now [-ferror-limit=] 20 errors generated. make: *** [RcppExports.o] Error 1 ERROR: compilation failed for package ‘HACSim’ ─ removing ‘/private/var/folders/wv/4_z4h7ns57g7qvd600qgd__w0000gn/T/RtmpKH90nC/Rinst9cc48afc544/HACSim’

ERROR: package installation failed Error in (function (command = NULL, args = character(), error_on_status = TRUE, : System command 'R' failed, exit status: 1, stdout + stderr (last 10 lines): E> /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/cmath:650:17: error: no template named 'numeric_limits' E> static_assert(numeric_limits<_FloatT>::radix == 2, "FloatT has incorrect radix"); E> ^ E> fatal error: too many errors emitted, stopping now [-ferror-limit=] E> 20 errors generated. E> make: ** [RcppExports.o] Error 1 E> ERROR: compilation failed for package ‘HACSim’ E> removing ‘/private/var/folders/wv/4_z4h7ns57g7qvd600qgd__w0000gn/T/RtmpKH90nC/Rinst9cc48afc544/HACSim’ E> ----------------------------------- E> ERROR: package installation failed Type .Last.error.trace to see where the error occurred

I now suspect something deeper is going on here, but it seems we're closer to resolving things. Specifically, this looks like a problem with Rcpp interacting with Big Sur.

UPDATE #2

I've made some more progress from downloading and running the following in the terminal:

https://github.com/rmacoslib/r-macos-rtools/releases/tag/v4.0.0

which was based on a response from this SO post:

https://stackoverflow.com/questions/58313047/cannot-compile-r-packages-with-c-code-after-updating-to-macos-catalina

Once this was done, I checked Homebrew again. Interestingly, CLT (and other info) is now visible.

Jarretts-MacBook-Pro-3:~ jarrettphillips$ brew config HOMEBREW_VERSION: 3.2.0 ORIGIN: https://github.com/Homebrew/brew HEAD: 09f7bc27a99469cf947431df4754737dfbadb31d Last commit: 3 weeks ago Core tap ORIGIN: https://github.com/Homebrew/homebrew-core Core tap HEAD: b1c76d0f6e481ae009775f96f89c6cd1c635822d Core tap last commit: 5 days ago Core tap branch: master HOMEBREW_PREFIX: /usr/local HOMEBREW_CASK_OPTS: [] HOMEBREW_DISPLAY: /private/tmp/com.apple.launchd.syQHtikHlQ/org.macosforge.xquartz:0 HOMEBREW_MAKE_JOBS: 4 Homebrew Ruby: 2.6.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby CPU: quad-core 64-bit broadwell Clang: 12.0.5 build 1205 Git: 2.10.1 => /usr/local/bin/git Curl: 7.64.1 => /usr/bin/curl macOS: 11.4-x86_64 CLT: 12.5.1.0.1.1623191612 Xcode: 12.5.1 XQuartz: 2.7.11 => /opt/X11

However, I'm still prompted to build additional R tools when I run devtools::build().

Any ideas?

gaborcsardi commented 2 years ago

This seems like a duplicate of #103 to me.