'Error in dyn.load(dll_copy_file) when building Rcpp package on Mac

I'm building my own Rcpp Package (name: RUtilities) on Mac. However, I encountered the following error when executing devtools::document()

** checking absolute paths in shared objects and dynamic libraries
─  DONE (RUtilities)
Error in dyn.load(dll_copy_file) : 
  unable to load shared object '/var/folders/70/0x058vd10ts57r4ck5j2j3s00000gn/T//RtmpIXnrlU/pkgload13d793cdb33ea/RUtilities.so':
  dlopen(/var/folders/70/0x058vd10ts57r4ck5j2j3s00000gn/T//RtmpIXnrlU/pkgload13d793cdb33ea/RUtilities.so, 0x0006): symbol not found in flat namespace '__RUtilities_test'

My current attempts:

  1. delete the .so, .o files in the src folder and rerun the code.
  2. delete the RUtilities.so file in the /var/folders/70/ folder.

However, the error persists.

This problem is very strange to me, because the same package can be installed correctly on my Linux server.

I suspect there is something wrong with the R version, since my Linux server uses R3.6, while my mac uses R4.1. Should I modify the Makevars file when the R version changes? My Makevars file looks like this right now:

PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
PKG_CPPFLAGS = -I../inst/include/


CXX_STD = CXX11
PKG_LIBS += $(shell ${R_HOME}/bin/Rscript -e "RcppParallel::RcppParallelLibs()")

Also, my Mac uses the Apple M1 chip. Is this chip the problem?

Any suggestions are welcomed! Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source