admin管理员组

文章数量:1384106

I've been using Posit's package manager for binary installs of package, and that works for most things. However, installing packages from source that require clang-compiling fail.

I think it's related to the using SDK: '' empty part ...

For example,

> install.packages("jsonlite")
Installing package into ‘/Users/r2/Library/R/4.4’
(as ‘lib’ is unspecified)
trying URL '.9.1.tar.gz'
Content type 'binary/octet-stream' length 1051291 bytes (1.0 MB)
==================================================
downloaded 1.0 MB

* installing *source* package ‘jsonlite’ ...
** package ‘jsonlite’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
using C compiler: ‘Apple clang version 16.0.0 (clang-1600.0.26.6)’
using SDK: ‘’
clang -I"/opt/homebrew/Cellar/r/4.4.3_1/lib/R/include" -DNDEBUG -Iyajl/api  -I/opt/homebrew/opt/gettext/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/xz/include -I/opt/homebrew/include     -fPIC  -g -O2  -c base64.c -o base64.o
clang -I"/opt/homebrew/Cellar/r/4.4.3_1/lib/R/include" -DNDEBUG -Iyajl/api  -I/opt/homebrew/opt/gettext/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/xz/include -I/opt/homebrew/include     -fPIC  -g -O2  -c collapse_array.c -o collapse_array.o
...
clang -I"/opt/homebrew/Cellar/r/4.4.3_1/lib/R/include" -DNDEBUG -Iyajl/api  -I/opt/homebrew/opt/gettext/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/xz/include -I/opt/homebrew/include     -fPIC  -g -O2  -c yajl/yajl_parser.c -o yajl/yajl_parser.o
clang -I"/opt/homebrew/Cellar/r/4.4.3_1/lib/R/include" -DNDEBUG -Iyajl/api  -I/opt/homebrew/opt/gettext/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/xz/include -I/opt/homebrew/include     -fPIC  -g -O2  -c yajl/yajl_tree.c -o yajl/yajl_tree.o
ar rcs yajl/libstatyajl.a yajl/yajl.o yajl/yajl_alloc.o yajl/yajl_buf.o yajl/yajl_encode.o yajl/yajl_gen.o yajl/yajl_lex.o yajl/yajl_parser.o yajl/yajl_tree.o
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -L/opt/homebrew/Cellar/r/4.4.3_1/lib/R/lib -L/opt/homebrew/opt/gettext/lib -L/opt/homebrew/opt/readline/lib -L/opt/homebrew/opt/xz/lib -L/opt/homebrew/lib -o jsonlite.so base64.o collapse_array.o collapse_object.o collapse_pretty.o escape_chars.o integer64_to_na.o is_datelist.o is_recordlist.o is_scalarlist.o modp_numtoa.o null_to_na.o num_to_char.o parse.o prettify.o push_parser.o r-base64.o register.o row_collapse.o transpose_list.o validate.o -Lyajl -lstatyajl -L/opt/homebrew/Cellar/r/4.4.3_1/lib/R/lib -lR -lintl -Wl,-framework -Wl,CoreFoundation
ld: archive member '/' not a mach-o file in '/private/var/folders/3f/0hlmq7rx34ddjqtlc1lqbxl80000gn/T/RtmpuoriDi/R.INSTALLae611eb747f2/jsonlite/src/yajl/libstatyajl.a'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [/opt/homebrew/Cellar/r/4.4.3_1/lib/R/share/make/shlib.mk:10: jsonlite.so] Error 1
ERROR: compilation failed for package ‘jsonlite’

That error is in R that was installed via homebrew, but it's also an issue with "R.app". Nearly identical output, but using the /Library/Framework/... paths for R include headers and such:

> install.packages("jsonlite", type='source')
Installing package into ‘/Users/r2/Library/R/4.4’
(as ‘lib’ is unspecified)
trying URL '.9.1.tar.gz'
Content type 'binary/octet-stream' length 1051291 bytes (1.0 MB)
==================================================
downloaded 1.0 MB

* installing *source* package ‘jsonlite’ ...
** package ‘jsonlite’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
using C compiler: ‘Apple clang version 16.0.0 (clang-1600.0.26.6)’
using SDK: ‘’
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -Iyajl/api  -I/opt/R/arm64/include     -fPIC  -falign-functions=64 -Wall -g -O2  -c base64.c -o base64.o
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -Iyajl/api  -I/opt/R/arm64/include     -fPIC  -falign-functions=64 -Wall -g -O2  -c collapse_array.c -o collapse_array.o
...
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -Iyajl/api  -I/opt/R/arm64/include     -fPIC  -falign-functions=64 -Wall -g -O2  -c yajl/yajl_parser.c -o yajl/yajl_parser.o
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -Iyajl/api  -I/opt/R/arm64/include     -fPIC  -falign-functions=64 -Wall -g -O2  -c yajl/yajl_tree.c -o yajl/yajl_tree.o
ar rcs yajl/libstatyajl.a yajl/yajl.o yajl/yajl_alloc.o yajl/yajl_buf.o yajl/yajl_encode.o yajl/yajl_gen.o yajl/yajl_lex.o yajl/yajl_parser.o yajl/yajl_tree.o
clang -arch arm64 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -L/Library/Frameworks/R.framework/Resources/lib -L/opt/R/arm64/lib -o jsonlite.so base64.o collapse_array.o collapse_object.o collapse_pretty.o escape_chars.o integer64_to_na.o is_datelist.o is_recordlist.o is_scalarlist.o modp_numtoa.o null_to_na.o num_to_char.o parse.o prettify.o push_parser.o r-base64.o register.o row_collapse.o transpose_list.o validate.o -Lyajl -lstatyajl -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: archive member '/' not a mach-o file in '/private/var/folders/3f/0hlmq7rx34ddjqtlc1lqbxl80000gn/T/RtmpVNvRR6/R.INSTALLb2f9120e3fb/jsonlite/src/yajl/libstatyajl.a'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [/Library/Frameworks/R.framework/Resources/share/make/shlib.mk:10: jsonlite.so] Error 1
ERROR: compilation failed for package ‘jsonlite’

Some basic info:

> R.version
               _                           
platform       aarch64-apple-darwin20      
arch           aarch64                     
os             darwin20                    
system         aarch64, darwin20           
status                                     
major          4                           
minor          4.2                         
year           2024                        
month          10                          
day            31                          
svn rev        87279                       
language       R                           
version.string R version 4.4.2 (2024-10-31)
nickname       Pile of Leaves              

Sys.which(c("gcc", "clang", "make"))
#                                          gcc 
#                               "/usr/bin/gcc" 
#                                        clang 
#                             "/usr/bin/clang" 
#                                         make 
# "/opt/homebrew/opt/make/libexec/gnubin/make"

Possibly relevant information:

  • This is Sequoia 15.3.2, and I have XCode 16.2 (16C5032a) installed.
  • This is not about jsonlite itself, it's any package that requires compilation. (Binary packages from Posit's PM work fine.)
  • This happens with R --no-site --vanilla as well, so it's not a matter of .Rprofile or other site files.
  • This happens with other package repos, such as from .9.1.tar.gz, same error.

Edit 1:

XCode details:

$ xcode-select -p
/Applications/Xcode.app/Contents/Developer
$ xcrun --sdk macosx --show-sdk-path
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk

Edit 2:

I am not attempting to compile R for MacOS, but following / prompts me to install gfortran*.pkg. After doing that successfully (which includes the need for xattr -cr ~/Downloads/gfortran*.pkg to be able to install it).

Additionally, I tried adding the following to my ~/.Renviron (restart R, check Sys.getenv("SDKROOT") is correct):

SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk

This results in the source compile reporting using SDK: ‘MacOSX.sdk’ (which is a change) but it still failed with the same error.

Lastly, I uninstalled brew's make, so now Sys.which("make") reports "/usr/bin/make".

I've been using Posit's package manager for binary installs of package, and that works for most things. However, installing packages from source that require clang-compiling fail.

I think it's related to the using SDK: '' empty part ...

For example,

> install.packages("jsonlite")
Installing package into ‘/Users/r2/Library/R/4.4’
(as ‘lib’ is unspecified)
trying URL 'https://packagemanager.posit.co/cran/latest/src/contrib/jsonlite_1.9.1.tar.gz'
Content type 'binary/octet-stream' length 1051291 bytes (1.0 MB)
==================================================
downloaded 1.0 MB

* installing *source* package ‘jsonlite’ ...
** package ‘jsonlite’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
using C compiler: ‘Apple clang version 16.0.0 (clang-1600.0.26.6)’
using SDK: ‘’
clang -I"/opt/homebrew/Cellar/r/4.4.3_1/lib/R/include" -DNDEBUG -Iyajl/api  -I/opt/homebrew/opt/gettext/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/xz/include -I/opt/homebrew/include     -fPIC  -g -O2  -c base64.c -o base64.o
clang -I"/opt/homebrew/Cellar/r/4.4.3_1/lib/R/include" -DNDEBUG -Iyajl/api  -I/opt/homebrew/opt/gettext/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/xz/include -I/opt/homebrew/include     -fPIC  -g -O2  -c collapse_array.c -o collapse_array.o
...
clang -I"/opt/homebrew/Cellar/r/4.4.3_1/lib/R/include" -DNDEBUG -Iyajl/api  -I/opt/homebrew/opt/gettext/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/xz/include -I/opt/homebrew/include     -fPIC  -g -O2  -c yajl/yajl_parser.c -o yajl/yajl_parser.o
clang -I"/opt/homebrew/Cellar/r/4.4.3_1/lib/R/include" -DNDEBUG -Iyajl/api  -I/opt/homebrew/opt/gettext/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/xz/include -I/opt/homebrew/include     -fPIC  -g -O2  -c yajl/yajl_tree.c -o yajl/yajl_tree.o
ar rcs yajl/libstatyajl.a yajl/yajl.o yajl/yajl_alloc.o yajl/yajl_buf.o yajl/yajl_encode.o yajl/yajl_gen.o yajl/yajl_lex.o yajl/yajl_parser.o yajl/yajl_tree.o
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -L/opt/homebrew/Cellar/r/4.4.3_1/lib/R/lib -L/opt/homebrew/opt/gettext/lib -L/opt/homebrew/opt/readline/lib -L/opt/homebrew/opt/xz/lib -L/opt/homebrew/lib -o jsonlite.so base64.o collapse_array.o collapse_object.o collapse_pretty.o escape_chars.o integer64_to_na.o is_datelist.o is_recordlist.o is_scalarlist.o modp_numtoa.o null_to_na.o num_to_char.o parse.o prettify.o push_parser.o r-base64.o register.o row_collapse.o transpose_list.o validate.o -Lyajl -lstatyajl -L/opt/homebrew/Cellar/r/4.4.3_1/lib/R/lib -lR -lintl -Wl,-framework -Wl,CoreFoundation
ld: archive member '/' not a mach-o file in '/private/var/folders/3f/0hlmq7rx34ddjqtlc1lqbxl80000gn/T/RtmpuoriDi/R.INSTALLae611eb747f2/jsonlite/src/yajl/libstatyajl.a'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [/opt/homebrew/Cellar/r/4.4.3_1/lib/R/share/make/shlib.mk:10: jsonlite.so] Error 1
ERROR: compilation failed for package ‘jsonlite’

That error is in R that was installed via homebrew, but it's also an issue with "R.app". Nearly identical output, but using the /Library/Framework/... paths for R include headers and such:

> install.packages("jsonlite", type='source')
Installing package into ‘/Users/r2/Library/R/4.4’
(as ‘lib’ is unspecified)
trying URL 'https://packagemanager.posit.co/cran/latest/src/contrib/jsonlite_1.9.1.tar.gz'
Content type 'binary/octet-stream' length 1051291 bytes (1.0 MB)
==================================================
downloaded 1.0 MB

* installing *source* package ‘jsonlite’ ...
** package ‘jsonlite’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
using C compiler: ‘Apple clang version 16.0.0 (clang-1600.0.26.6)’
using SDK: ‘’
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -Iyajl/api  -I/opt/R/arm64/include     -fPIC  -falign-functions=64 -Wall -g -O2  -c base64.c -o base64.o
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -Iyajl/api  -I/opt/R/arm64/include     -fPIC  -falign-functions=64 -Wall -g -O2  -c collapse_array.c -o collapse_array.o
...
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -Iyajl/api  -I/opt/R/arm64/include     -fPIC  -falign-functions=64 -Wall -g -O2  -c yajl/yajl_parser.c -o yajl/yajl_parser.o
clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -Iyajl/api  -I/opt/R/arm64/include     -fPIC  -falign-functions=64 -Wall -g -O2  -c yajl/yajl_tree.c -o yajl/yajl_tree.o
ar rcs yajl/libstatyajl.a yajl/yajl.o yajl/yajl_alloc.o yajl/yajl_buf.o yajl/yajl_encode.o yajl/yajl_gen.o yajl/yajl_lex.o yajl/yajl_parser.o yajl/yajl_tree.o
clang -arch arm64 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -L/Library/Frameworks/R.framework/Resources/lib -L/opt/R/arm64/lib -o jsonlite.so base64.o collapse_array.o collapse_object.o collapse_pretty.o escape_chars.o integer64_to_na.o is_datelist.o is_recordlist.o is_scalarlist.o modp_numtoa.o null_to_na.o num_to_char.o parse.o prettify.o push_parser.o r-base64.o register.o row_collapse.o transpose_list.o validate.o -Lyajl -lstatyajl -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: archive member '/' not a mach-o file in '/private/var/folders/3f/0hlmq7rx34ddjqtlc1lqbxl80000gn/T/RtmpVNvRR6/R.INSTALLb2f9120e3fb/jsonlite/src/yajl/libstatyajl.a'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [/Library/Frameworks/R.framework/Resources/share/make/shlib.mk:10: jsonlite.so] Error 1
ERROR: compilation failed for package ‘jsonlite’

Some basic info:

> R.version
               _                           
platform       aarch64-apple-darwin20      
arch           aarch64                     
os             darwin20                    
system         aarch64, darwin20           
status                                     
major          4                           
minor          4.2                         
year           2024                        
month          10                          
day            31                          
svn rev        87279                       
language       R                           
version.string R version 4.4.2 (2024-10-31)
nickname       Pile of Leaves              

Sys.which(c("gcc", "clang", "make"))
#                                          gcc 
#                               "/usr/bin/gcc" 
#                                        clang 
#                             "/usr/bin/clang" 
#                                         make 
# "/opt/homebrew/opt/make/libexec/gnubin/make"

Possibly relevant information:

  • This is Sequoia 15.3.2, and I have XCode 16.2 (16C5032a) installed.
  • This is not about jsonlite itself, it's any package that requires compilation. (Binary packages from Posit's PM work fine.)
  • This happens with R --no-site --vanilla as well, so it's not a matter of .Rprofile or other site files.
  • This happens with other package repos, such as from https://cloud.r-project./src/contrib/jsonlite_1.9.1.tar.gz, same error.

Edit 1:

XCode details:

$ xcode-select -p
/Applications/Xcode.app/Contents/Developer
$ xcrun --sdk macosx --show-sdk-path
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk

Edit 2:

I am not attempting to compile R for MacOS, but following https://mac.r-project./tools/ prompts me to install gfortran*.pkg. After doing that successfully (which includes the need for xattr -cr ~/Downloads/gfortran*.pkg to be able to install it).

Additionally, I tried adding the following to my ~/.Renviron (restart R, check Sys.getenv("SDKROOT") is correct):

SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk

This results in the source compile reporting using SDK: ‘MacOSX.sdk’ (which is a change) but it still failed with the same error.

Lastly, I uninstalled brew's make, so now Sys.which("make") reports "/usr/bin/make".

Share Improve this question edited Mar 19 at 15:51 r2evans asked Mar 19 at 14:56 r2evansr2evans 162k7 gold badges86 silver badges168 bronze badges Recognized by R Language Collective 9
  • 2 What does bash % xcode-select -p print? It should be something like /Library/Developer/CommandLineTools. Also check if there are settings in bashrc that interfere with the default. Lastly maybe include LDFLAGS=-L/usr/local/lib -Wl,-rpath,/usr/local/lib in ~/.R/Makevars – Andre Wildberg Commented Mar 19 at 15:40
  • 1 Thank you for asking this. I believe I have the same issue and I have given up for now. I suspect the issue might result from some cruft left over after OS updates that made my working setup defunct. I don’t know enough to even start fixing it. I don’t need to compile packages urgently enough to do a clean OS install on that machine. – Roland Commented Mar 19 at 16:08
  • 1 If you don't work it out based on what you see here, I'd post to R-SIG-Mac. You probably need to be a subscriber, see stat.ethz.ch/mailman/listinfo/r-sig-mac to sign up. – user2554330 Commented Mar 19 at 16:44
  • 1 Before reinstalling the OS try installing R from source. That should give your installation the right paths and normally results in a working source package installation environment. I can assure you that a clean MacOS15 with clang16 (only Command Line Tools installed) works flawlessly. Even openmp works with libomp. – Andre Wildberg Commented Mar 19 at 17:19
  • 1 Check which ar you are using. Should be /usr/bin/ar. Its a universal binary for which file /usr/bin/ar gives /usr/bin/ar: Mach-O universal binary with 2 architectures: .... The home brew one might fail. – Andre Wildberg Commented Mar 19 at 20:37
 |  Show 4 more comments

2 Answers 2

Reset to default 1

Posting my comment as an answer, glad that solved it:

Check which ar you are using. It should be /usr/bin/ar

Its a universal binary

% file /usr/bin/ar
/usr/bin/ar: Mach-O universal binary with 2 architectures: ...

The homebrew one might fail.

I think you're right, the line using SDK: ‘’ is informative. I see using SDK: ‘MacOSX15.1.sdk’.

Did you follow the instructions on https://mac.r-project./tools/ to install the tools?

The other difference I see is that you have make from homebrew, whereas mine is in /usr/bin. Maybe you have the Homebrew directory earlier in the PATH than /usr/bin? I have /opt/homebrew/bin in the PATH, but it comes after /opt/R/arm64/bin, /usr/local/bin, some junk added by Apple, and /usr/bin.

BTW, the line the install code uses to find the SDK is

try(system2("xcrun", "--show-sdk-path", TRUE, TRUE))

What does that give you?

本文标签: xcodecompile R packages on macosStack Overflow