r-lib / pkgbuild

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

pkgbuild::check_build_tools() failing even though developer software is installed #172

Closed bertozzivill closed 12 months ago

bertozzivill commented 12 months ago

I am new to building packages, and am working through the first chapter of R Packages as a tutorial. Everything was going well until I got to the first check() command, at which point I received a popup with the following message:

Screenshot 2023-09-26 at 4 50 50 PM

I clicked "yes", but nothing happened and I was left with an error message that I neglected to record. Running pkgbuild::check_build_tools(debug = TRUE) just got me in an endless loop of the same error.

Upon googling "R build tools for mac", I found this page and followed the instructions for downloading Xcode, gfortran, and xquartz. All of the intermediate tests recommended by the page show correct installation:

Screenshot 2023-09-27 at 3 03 48 PM

However, when I get to the step of going back to run pkgbuild::check_build_tools(), I yet again found myself with an error, though I can't confirm whether it's the same or different error as before installing Xcode:

Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c
using C compiler: ‘Homebrew clang version 13.0.1’
using SDK: ‘’
/usr/local/opt/llvm/bin/clang -fopenmp -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/usr/local/opt/gettext/include -I/usr/local/opt/llvm/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include    -fPIC  -g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe -c foo.c -o foo.o
/usr/local/opt/llvm/bin/clang -fopenmp -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/opt/gettext/lib -L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib -o foo.so foo.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: warning: -single_module is obsolete
ld: warning: -multiply_defined is obsolete
ld: warning: -single_module is obsolete
ld: warning: -multiply_defined is obsolete
ld: library 'System' not found
clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [foo.so] Error 1
Error: Could not find tools necessary to compile a package
Call `pkgbuild::check_build_tools(debug = TRUE)` to diagnose the problem.

I restarted my machine, same error. I re-installed R and RStudio, still same error. I've googled the specific clang-13 error, but do not feel confident enough in any of the answers to go messing around in my Xcode files when I'm unfamiliar with the system. Can you advise?

As a note, my colleague also got the RStudio popup, but when she clicked "Yes", the system began installing Xcode command line tools. I'm not sure why the same didn't happen for me?

I'm on a 2023 MacBook (M2 chip, Ventura 13.5.1). R Version 4.3.1 and RStudio Version 2023.06.2+561. I'm not sure what other info you need (.Makevars, SessionInfo, etc) and don't want to clog the issue so I'll wait for your suggestions. Thank you!

gaborcsardi commented 12 months ago

First remove the homebrew compilers, they are not needed, not even homebrew is compiled with the homebrew compilers. Then install the xcode command line tools, RStudio needs these. (R and pkgbuild don't, so you should be able to use R and pkgbuild from a terminal without them.)

Then try calling pkgbuild::check_build_tools() from a terminal. If that works then try calling it from RStudio.

Btw. inserting images here is not great, because I cannot copy-paste the text from them. Try inserting the text between markdown ``` lines, so the formatting is preserved.

bertozzivill commented 12 months ago

Thank you for the formatting note, I have updated my issue with the error message in markdown.

So you're saying that installing Xcode does not install the Xcode command line tools? If that's the case I'll uninstall Xcode entirely and install just the command line tools.

was it necessary for me to install gfortran and xquartz? are they causing any harm by being installed?

For the homebrew compiler issue, would you be able to point me to a resource for how to do this? When I google "remove homebrew compiler" the only thing that shows up is instructions to uninstall homebrew itself, which I would prefer not to do.

Many thanks for your help!

gaborcsardi commented 12 months ago

So you're saying that installing Xcode does not install the Xcode command line tools?

Yes.

was it necessary for me to install gfortran and xquartz?

Yes, if you want to compile Fortran programs, and yes.

are they causing any harm by being installed?

No.

would you be able to point me to a resource for how to do this?

Call

brew uninstall <package>

IDK what the "Homebrew clang version 13.0.1" package is called. Call brew list and search there.

bertozzivill commented 12 months ago

got it-- for the record, the "Homebrew clang version 13.0.1" package is llvm@13

uninstalling xcode and installing just the command line tools worked perfectly!

After I'd uninstalled Xcode and deleted my ~/Library/Developer folder, running clang in the terminal automatically prompted my OS to download and install developer tools. As soon as it was done installing everything worked great.

Looking forward to building some packages now :)