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
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,
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