r-quantities / units

Measurement units for R
https://r-quantities.github.io/units
175 stars 28 forks source link

Installation error in ARM64 machine #262

Closed sigmafelix closed 3 years ago

sigmafelix commented 3 years ago

Hello, I try to install units package in my ARM64 machine. Since the udunits2 package binary was not available, I built the udunits2 first, then used the code as below:

install.packages('units', INSTALL_opts='UDUNITS2_LIBS=/usr/local/lib/udunits2/lib')

Then it prints the error messages as below:

[truncated]
** libs
g++ -std=gnu++11 -I"/usr/local/lib/R/include" -DNDEBUG -DUDUNITS2_DIR=0   -I/usr/local/include -I'/Users/isong/Library/R/4.0/library/Rcpp/include' -I/usr/local/include   -fPIC  -g -O2  -c RcppExports.cpp -o RcppExports.o
gcc -I"/usr/local/lib/R/include" -DNDEBUG -DUDUNITS2_DIR=0   -I/usr/local/include -I'/Users/isong/Library/R/4.0/library/Rcpp/include' -I/usr/local/include   -fPIC  -g -O2  -c io.c -o io.o
In file included from io.c:6:
In file included from /usr/local/include/udunits2.h:68:
/usr/local/include/converter.h:11:9: warning: 'snprintf' macro redefined
      [-Wmacro-redefined]
#define snprintf c99_snprintf
        ^
/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/secure/_stdio.h:56:9: note: 
      previous definition is here
#define snprintf(str, len, ...) \
        ^
1 warning generated.
g++ -std=gnu++11 -I"/usr/local/lib/R/include" -DNDEBUG -DUDUNITS2_DIR=0   -I/usr/local/include -I'/Users/isong/Library/R/4.0/library/Rcpp/include' -I/usr/local/include   -fPIC  -g -O2  -c udunits.cpp -o udunits.o
g++ -std=gnu++11 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -o units.so RcppExports.o io.o udunits.o -lexpat -lexpat -ludunits2 -Wl,-framework -Wl,CoreFoundation
installing to /Users/isong/Library/R/4.0/library/units/libs
** R
** demo
** 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
Error: package or namespace load failed for ‘units’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/Users/isong/Library/R/4.0/library/units/libs/units.so':
  dlopen(/Users/isong/Library/R/4.0/library/units/libs/units.so, 6): Library not loaded: @rpath/libudunits2.dylib
  Referenced from: /Users/isong/Library/R/4.0/library/units/libs/units.so
  Reason: image not found
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/Users/isong/Library/R/4.0/library/units’

Does anyone have an idea on this problem?

Thank you.

edzer commented 3 years ago

Do you have the udunits library installed in two places?

Enchufa2 commented 3 years ago

A macro defined in two places. AFAIK macOS's SDK has an opinionated way of including headers of standard libraries, and this even varies across SDK versions. There is a standardized way of compiling R stuff on macOS x86_64 that simply works. This package is tested in such platforms. I suppose that R would have to standardize a similar configuration for the new ARM chip. Until then, this is no man's land. The best place to ask for help about this is the R-SIG-Mac mailing list. I suggest you try there, because we're no macOS users.

edzer commented 3 years ago

The macro is only a warning, the package was compiled nevertheless, but didn't pass the load step.

Enchufa2 commented 3 years ago

You're right, I skimmed through too quickly. The INSTALL_opts argument doesn't seem to be the right one for this. I think that configure.args is what @sigmafelix is looking for. In fact, this is the help message we have when the configuration fails:

--------------------------------------------------------------------------------
  Configuration failed because ${UD_ERROR}. Try installing:
    * deb: libudunits2-dev (Debian, Ubuntu, ...)
    * rpm: udunits2-devel (Fedora, EPEL, ...)
    * brew: udunits (OSX)
  If udunits2 is already installed in a non-standard location, use:
    --configure-args='--with-udunits2-lib=/usr/local/lib'
  if the library was not found, and/or:
    --configure-args='--with-udunits2-include=/usr/include/udunits2'
  if the header was not found, replacing paths with appropriate values.
  You can alternatively set UDUNITS2_INCLUDE and UDUNITS2_LIBS manually.
--------------------------------------------------------------------------------
sigmafelix commented 3 years ago

@edzer Yes. The problem occurs when the installation process is finalized. As I never experienced this type of problem, I opened an issue here. @Enchufa2 Thank you for letting me know R-SIG-Mac. I will send a question to it too. It is surprising to see the installation process was going smoothly at first even though the parameter was inaccurately passed.

edzer commented 3 years ago

Was your yes an answer to my question

Do you have the udunits library installed in two places?

sigmafelix commented 3 years ago

@edzer No I installed udunits library just in /usr/local/lib.

edzer commented 3 years ago

From the error message it looks like you did that in a way that didn't give the load process access to @rpath/libudunits2.dylib. Have you tried installing the CRAN binary package of units?

sigmafelix commented 3 years ago

Following your comments, I tried the code install.packages('units', type = 'mac.binary'). The installation process was done without error, but when I tried loading the units, it resulted in error messages related to an architecture problem:

> library(units)
Error: package or namespace load failed for ‘units’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/Users/isong/Library/R/4.0/library/units/libs/units.so':
  dlopen(/Users/isong/Library/R/4.0/library/units/libs/units.so, 6): no suitable image found.  Did find:
    /Users/isong/Library/R/4.0/library/units/libs/units.so: mach-o, but wrong architecture
    /Users/isong/Library/R/4.0/library/units/libs/units.so: mach-o, but wrong architecture
edzer commented 3 years ago

For sf and rgdal this has been resolved, see https://stat.ethz.ch/pipermail/r-sig-mac/2020-November/013783.html . @s-u does package units (and the udunits library it interfaces) need extra treatment, or should the current Mac CRAN binaries work on ARM64? Or am I now confusing the BigSur update and the ARM64 compatibility issues?

Enchufa2 commented 3 years ago

Yes, the new version of the operating system, BigSur, is one thing, and the new architecture is another thing. CRAN binaries are for x86_64, not ARM64. So in this new architecture, R-on-Mac users have two options: either to compile everything locally or to use the low-level translator (Rosetta?).

Enchufa2 commented 3 years ago

Closing this. Please, don't hesitate to reopen if there's something we can do.

s-u commented 3 years ago

@sigmafelix the original error is due to the fact that the udunit library you are using does not have proper id so can't be reliably linked to. You will have to use something like

install_name_tool -id /usr/local/lib/udunits2/lib/libudunits2.dylib /usr/local/lib/udunits2/lib/libudunits2.dylib

and the re-compile the package. The other alternative is to edit the configuration files to make sure /usr/local/lib/udunits2/lib (really bad location, BTW) is on the DYLIB_LIBRARY_PATH.

Either way the issue is with your library, not the package.

sigmafelix commented 3 years ago

@s-u Thank you for letting me know. Now I don't have the machine (Mac ARM64) in which I got the problem. I hope other users will get help from this thread.

Enchufa2 commented 3 years ago

Thanks, @s-u, for taking a look.