[R-pkg-devel] Fwd: cmake based compilation works on macOS but fails on Linux machines

Satyaprakash Nayak @n248 @end|ng |rom corne||@edu
Tue Jul 19 05:22:52 CEST 2022


Hi everyone

I am trying to compile a package which provides an interface to the Ceres
solver <http://ceres-solver.org/> C++ library for large-scale,
unconstrained optimization. The requirements for compiling this library are
non-trivial and I am using cmake based compilation into static libraries,
following the steps in the excellent nloptr package
<https://github.com/astamm/nloptr>

The package code can be found here <https://github.com/sn248/ceres>

The package requires Eigen
<https://eigen.tuxfamily.org/index.php?title=Main_Page>, gflags
<https://gflags.github.io/gflags/> and glog <https://github.com/google/glog>
as requirements and they are all compiled from source before compiling
ceres from source using cmake. The package successfully compiles and I am
able to run the helloworld example in the library on my macOS (10.15.7),
see the example on the github page <https://github.com/sn248/ceres>. I am
also able to compile on rhub's mac OS machines (i.e., macOS 10.13.6 High
Sierra, R-release, brew AND macOS 10.13.6 High Sierra, R-release, CRAN's
setup). However, _exactly_ the same package fails to compile on Ubuntu and
Debian machines on rhub.

In summary,

Case 1 - When my Makevars is the following, the package compiles
successfully on my local macOS and rhub's macOS (all except Apple Silicon,
M1).

CXX_STD = CXX17
> PKG_CPPFLAGS = -I../inst/include
> PKG_LDFLAGS = ../inst/
> PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) -L$(PKG_LDFLAGS)
> ../inst/libceres.a ../inst/libgflags.a ../inst/libgflags_nothreads.a
> ../inst/libglog.a


But I get the following error on Linux machines (e.g., Debian Linux,
R-devel, GCC)

Error: package or namespace load failed for 'ceres' in dyn.load(file,
> DLLpath = DLLpath, ...):
>  unable to load shared object
> '/home/docker/R/00LOCK-ceres/00new/ceres/libs/ceres.so':
>   /home/docker/R/00LOCK-ceres/00new/ceres/libs/ceres.so: undefined symbol:
> _ZN6google14FlagRegistererC1IiEEPKcS3_S3_PT_S5_
> Error: loading failed


Case 2 - When my Makevars is the following, I get error shown below on my
local machine (macOS 10.15.7)

CXX_STD = CXX17
> PKG_CPPFLAGS = -I../inst/include
> PKG_LDFLAGS = ../inst/
> PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) -L$(PKG_LDFLAGS) -lceres
> -lgflags -lgflags_nothreads -lglog


Error message:

Error in dyn.load(dll_copy_file) :
>   unable to load shared object
> '/var/folders/nk/j257crk53f9__1tfl_r91gm40000gq/T//Rtmp75jns4/pkgloadfebd425b03cc/ceres.so':
>
> dlopen(/var/folders/nk/j257crk53f9__1tfl_r91gm40000gq/T//Rtmp75jns4/pkgloadfebd425b03cc/ceres.so,
> 6): Library not loaded: @rpath/libglog.1.dylib
>   Referenced from:
> /private/var/folders/nk/j257crk53f9__1tfl_r91gm40000gq/T/Rtmp75jns4/pkgloadfebd425b03cc/ceres.so
>   Reason: image not found


I am thinking this is because of the fact that glog has the default cmake
option of being built as a shared library (although a static library can
also be built and is being built in the package).  However, I don't know
how I can link the shared library libglog.dylib.

To make the matters more interesting, if I install the packages on an
Ubuntu system (i.e., rocker/rstudio <https://rocker-project.org/images/>
with system installs of Eigen, glog and gflags), the package compiles
successfully with Makevars as in Case 2.

I would be very thankful if any help/pointers can be provided to compile
the package on Linux machines. Additionally, it seems on Apple Mac (M1) and
Solaris machines the compilation of package fails due to cmake
non-availability, how can I compile on those platforms?

Thanks
Satya

	[[alternative HTML version deleted]]



More information about the R-package-devel mailing list