Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An installation error on mac #150

Closed
mattocci27 opened this issue Oct 19, 2022 · 5 comments
Closed

An installation error on mac #150

mattocci27 opened this issue Oct 19, 2022 · 5 comments

Comments

@mattocci27
Copy link

Here is the R session information and the error code.

[ins] r$> devtools::session_info()                                                                                            
─ Session info ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.2.1 (2022-06-23)
 os       macOS Monterey 12.6
 system   aarch64, darwin21.6.0
 ui       unknown
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       Asia/Shanghai
 date     2022-10-19
 pandoc   2.19.2 @ /opt/homebrew/bin/pandoc
> install.packages("V8")
Installing package into ‘/opt/homebrew/lib/R/4.2/site-library’
(as ‘lib’ is unspecified)
trying URL 'https://mirror.lzu.edu.cn/CRAN/src/contrib/V8_4.2.1.tar.gz'
Content type 'application/octet-stream' length 682947 bytes (666 KB)
==================================================
downloaded 666 KB

* installing *source* package ‘V8’ ...
** package ‘V8’ successfully unpacked and MD5 sums checked
** using staged installation
Found C++17 compiler: clang++
Using autobrew bundle: v8-9.6.180.12-arm64_big_sur.tar.xz
Using CXXCPP=clang++ -std=gnu++17 -E
Using PKG_CFLAGS=-I/private/var/folders/1v/_ypjfm2d71bf8nf01_2jk2t00000gn/T/Rtmpr8SquK/R.INSTALL5e53f433ae1/V8/.deps/include
Using PKG_LIBS=-L/private/var/folders/1v/_ypjfm2d71bf8nf01_2jk2t00000gn/T/Rtmpr8SquK/R.INSTALL5e53f433ae1/V8/.deps/lib -lv8
Running feature test for pointer compression...
Undefined symbols for architecture arm64:
  "v8::platform::NewDefaultPlatform(int, v8::platform::IdleTaskSupport, v8::platform::InProcessStackDumping, std::__1::unique_ptr<v8::TracingController, std::__1::default_delete<v8::TracingController> >)", referenced from:
      _main in test-9cf2bf.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Enabling pointer compression
** libs
rm -f V8.so RcppExports.o bindings.o
clang++ -std=gnu++17 -I"/opt/homebrew/Cellar/r/4.2.1_4/lib/R/include" -DNDEBUG -I/private/var/folders/1v/_ypjfm2d71bf8nf01_2jk2t00000gn/T/Rtmpr8SquK/R.INSTALL5e53f433ae1/V8/.deps/include -DV8_COMPRESS_POINTERS -I'/opt/homebrew/lib/R/4.2/site-library/Rcpp/include' -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 RcppExports.cpp -o RcppExports.o
clang++ -std=gnu++17 -I"/opt/homebrew/Cellar/r/4.2.1_4/lib/R/include" -DNDEBUG -I/private/var/folders/1v/_ypjfm2d71bf8nf01_2jk2t00000gn/T/Rtmpr8SquK/R.INSTALL5e53f433ae1/V8/.deps/include -DV8_COMPRESS_POINTERS -I'/opt/homebrew/lib/R/4.2/site-library/Rcpp/include' -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 bindings.cpp -o bindings.o
clang++ -std=gnu++17 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/opt/homebrew/Cellar/r/4.2.1_4/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 V8.so RcppExports.o bindings.o -L/private/var/folders/1v/_ypjfm2d71bf8nf01_2jk2t00000gn/T/Rtmpr8SquK/R.INSTALL5e53f433ae1/V8/.deps/lib -lv8 -L/opt/homebrew/Cellar/r/4.2.1_4/lib/R/lib -lR -lintl -Wl,-framework -Wl,CoreFoundation
ld: warning: -undefined dynamic_lookup may not work with chained fixups
installing to /opt/homebrew/lib/R/4.2/site-library/00LOCK-V8/00new/V8/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘V8’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/opt/homebrew/lib/R/4.2/site-library/00LOCK-V8/00new/V8/libs/V8.so':
  
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/opt/homebrew/lib/R/4.2/site-library/V8’

The downloaded source packages are in
        ‘/private/var/folders/1v/_ypjfm2d71bf8nf01_2jk2t00000gn/T/Rtmp6tnEGx/downloaded_packages’
Warning message:
In install.packages("V8") :
  installation of package ‘V8’ had non-zero exit status
@jeroen
Copy link
Owner

jeroen commented Oct 19, 2022

Hmm I don't recognize his warning, never seen that before, it may be something new in the latest xcode.

ld: warning: -undefined dynamic_lookup may not work with chained fixups

Is there any reason you are compiling the source package, instead of using the pre-compiled binary? Can you try

install.packages("V8", type = 'mac.binary')

@mattocci27
Copy link
Author

Thanks. Yes, it used to work until I upgraded xcode. I tried install.packages("V8", type = 'mac.binary') but it downloaded the x86_64 version.

[ins] r$> library(V8)
Error: package or namespace load failed for ‘V8’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/opt/homebrew/lib/R/4.2/site-library/V8/libs/V8.so':
  dlopen(/opt/homebrew/lib/R/4.2/site-library/V8/libs/V8.so, 0x0006): tried: '/opt/homebrew/lib/R/4.2/site-library/V8/libs/V8.so' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e)))

Next, I downloaded a macOS binary (arm64) from CRAN and tried remotes::install_local("V8_4.2.1.tgz"). Now I have a different error.

[ins] r$> library(V8)
Error: package or namespace load failed for ‘V8’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/opt/homebrew/lib/R/4.2/site-library/V8/libs/V8.so':
  dlopen(/opt/homebrew/lib/R/4.2/site-library/V8/libs/V8.so, 0x0006): Library not loaded: '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libR.dylib'
  Referenced from: '/opt/homebrew/lib/R/4.2/site-library/V8/libs/V8.so'
  Reason: tried: '/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libR.dylib' (no such file), '/usr/local/lib/libR.dylib' (no such file), '/usr/lib/libR.dylib' (no such file)

@jeroen
Copy link
Owner

jeroen commented Oct 19, 2022

Ah ok I guess the binary only works if you use the official R from CRAN and not the homebrew version of R. You can probably simplify your life with

brew remove r
brew install --cask r

@mattocci27
Copy link
Author

Wow, now install.packages("V8") is woking. I will never use brew install r👍

@kevinushey
Copy link

kevinushey commented Oct 19, 2022

I was able to reproduce the error after installing v8 from Homebrew; e.g.

brew install v8

Here's some more verbose output...

Running feature test for pointer compression...
Apple clang version 14.0.0 (clang-1400.0.29.102)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple arm64-apple-macosx12.0.0 -Wundef-prefix=TARGET_OS_ -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -mframe-pointer=non-leaf -fno-strict-return -fno-rounding-math -funwind-tables=2 -fobjc-msgsend-selector-stubs -target-sdk-version=12.3 -fvisibility-inlines-hidden-static-local-var -target-cpu apple-m1 -target-feature +v8.5a -target-feature +fp-armv8 -target-feature +neon -target-feature +crc -target-feature +crypto -target-feature +dotprod -target-feature +fp16fml -target-feature +ras -target-feature +lse -target-feature +rdm -target-feature +rcpc -target-feature +zcm -target-feature +zcz -target-feature +fullfp16 -target-feature +sm4 -target-feature +sha3 -target-feature +sha2 -target-feature +aes -target-abi darwinpcs -fallow-half-arguments-and-returns -debug-info-kind=standalone -dwarf-version=4 -debugger-tuning=lldb -target-linker-version 819.6 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/14.0.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -I /opt/homebrew/opt/gettext/include -I /opt/homebrew/opt/readline/include -I /opt/homebrew/opt/xz/include -I /opt/homebrew/include -I /Users/kevin/r/pkg/V8/.deps/include -D V8_ENABLE_CHECKS -I/usr/local/include -stdlib=libc++ -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/14.0.0/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -O2 -Wno-reorder-init-list -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-final-dtor-non-final-class -Wno-extra-semi-stmt -Wno-misleading-indentation -Wno-quoted-include-in-framework-header -Wno-implicit-fallthrough -Wno-enum-enum-conversion -Wno-enum-float-conversion -Wno-elaborated-enum-base -Wno-reserved-identifier -Wno-gnu-folding-constant -Wno-cast-function-type -Wno-bitwise-instead-of-logical -std=gnu++17 -fdeprecated-macro -fdebug-compilation-dir=/Users/kevin/r/pkg/V8 -ferror-limit 19 -pthread -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fno-cxx-modules -fcxx-exceptions -fexceptions -fmax-type-align=16 -fcommon -fcolor-diagnostics -vectorize-loops -vectorize-slp -clang-vendor-feature=+messageToSelfInClassMethodIdReturnType -clang-vendor-feature=+disableInferNewAvailabilityFromInit -clang-vendor-feature=+disableNonDependentMemberExprInCurrentInstantiation -fno-odr-hash-protocols -clang-vendor-feature=+enableAggressiveVLAFolding -clang-vendor-feature=+revert09abecef7bbf -clang-vendor-feature=+thisNoAlignAttr -clang-vendor-feature=+thisNoNullAttr -mllvm -disable-aligned-alloc-awareness=1 -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /var/folders/9n/3nxsgkrj0rlfx196kzdttpww0000gn/T/test-6bec6d.o -x c++ tools/test.cpp
clang -cc1 version 14.0.0 (clang-1400.0.29.102) default target arm64-apple-darwin21.6.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /opt/homebrew/opt/gettext/include
 /opt/homebrew/opt/readline/include
 /opt/homebrew/opt/xz/include
 /opt/homebrew/include
 /Users/kevin/r/pkg/V8/.deps/include
 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/14.0.0/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -dynamic -arch arm64 -platform_version macos 12.0.0 12.3 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -o pctest -L/opt/homebrew/opt/gettext/lib -L/opt/homebrew/opt/readline/lib -L/opt/homebrew/opt/xz/lib -L/opt/homebrew/lib -L/Users/kevin/r/pkg/V8/.deps/lib -L/usr/local/lib /var/folders/9n/3nxsgkrj0rlfx196kzdttpww0000gn/T/test-6bec6d.o -lv8 -ldl -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/14.0.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture arm64:
  "v8::platform::NewDefaultPlatform(int, v8::platform::IdleTaskSupport, v8::platform::InProcessStackDumping, std::__1::unique_ptr<v8::TracingController, std::__1::default_delete<v8::TracingController> >)", referenced from:
      _main in test-6bec6d.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I think there's two issues. First, the pointer compression test code needs to make sure the bundled libv8 compiler flags come first, before anything set by R:

V8/configure

Lines 123 to 134 in 196359b

# Test if we need to enable pointer compression (Usually 8.4 and up)
echo "Running feature test for pointer compression..."
${CXX} ${CPPFLAGS} ${PKG_CFLAGS} ${CXXFLAGS} -DV8_ENABLE_CHECKS tools/test.cpp -o pctest ${LDFLAGS} ${PKG_LIBS} -ldl -pthread
{ ./pctest; } 2>> configure.log
if [ $? -eq 0 ]; then
echo "Pointer compression not needed"
PKG_CFLAGS="$PKG_CFLAGS -DV8_ENABLE_CHECKS"
else
echo "Enabling pointer compression"
PKG_CFLAGS="$PKG_CFLAGS -DV8_COMPRESS_POINTERS"
fi
rm -Rf pctest*

That is, the PKG_* flags should come first, so that those locations are preferred to anything R was compiled with.

Second, V8 needs a way to tell Homebrew R to link with the version of libv8 that it's providing. Unfortunately, PKG_LIBS is not enough as the library flags get set after the R linker flags:

clang++ -std=gnu++17 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/opt/homebrew/Cellar/r/4.2.1_4/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 V8.so RcppExports.o bindings.o -L/Users/kevin/r/pkg/V8/.deps/lib -lv8 -L/opt/homebrew/Cellar/r/4.2.1_4/lib/R/lib -lR -lintl -Wl,-framework -Wl,CoreFoundation

I don't see a clean way of doing this except perhaps with a src/Makefile rather than a src/Makevars, since AFAICS there isn't a clean place for packages to provide linker flags that come before the ones set by R.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants