[Rd] Using R to wrap NREL's SSC library

Ezra Tucker ezr@ @end|ng |rom |@ndtucker@com
Tue Nov 9 17:19:13 CET 2021


Hi all,

I'm attempting to write a package that wraps a pre-compiled library
which is part of the SAM application, put out by NREL, available here:
https://sam.nrel.gov/download.html
or the source for the library only, available here:
https://github.com/nrel/ssc
For a variety of reasons, I'd rather not recompile the library myself,
I'd rather use the precompiled version.

I'm using the linux version right now, for mac or windows some of the
paths might be different.

In linux, the installation of SAM goes into /opt/SAM/<version>. There's
a single .h file I'm concerned with, which is in
/opt/SAM/2020.11.29/linux_64/sscapi.h and the library itself
/opt/SAM/2020.11.29/linux_64/ssc.so.

Steps I have taken:
- I duplicated it in the same directory and renamed the duplicate
libssc.so
- New package with Rcpp entitled "ssc"
- in my Makevars file I put
PKG_CPPFLAGS=-I/opt/SAM/2020.11.29/linux_64
PKG_LIBS=-L/opt/SAM/2020.11.29/linux_64 -lssc

- my NAMESPCAE file has
importFrom(Rcpp,sourceCpp)
useDynLib(ssc, .register = TRUE)

- Single function to get the library's version from the library itself
(just to make sure things are working), in ssc_version.cpp:

#include <Rcpp.h>
#include "sscapi.h"
using namespace Rcpp;

// [[Rcpp::export]]
int R_ssc_version() {
  int version = ssc_version();
  return version;
}

I'm running into a problem actually installing the package though. When
running

> devtools::check("/path/to/ssc")

The output is:
─  installing *source* package ‘ssc’ ...
   ** using staged installation
   ** libs
   g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -
I/opt/SAM/2020.11.29/linux_64 -I'/home/ezra/R/x86_64-pc-linux-gnu-
library/4.1/Rcpp/include'    -fpic  -g -O2 -fdebug-prefix-map=/build/r-
base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -
Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -UNDEBUG -
Wall -pedantic -g -O0 -fdiagnostics-color=always -c RcppExports.cpp -o
RcppExports.o
   g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -
I/opt/SAM/2020.11.29/linux_64 -I'/home/ezra/R/x86_64-pc-linux-gnu-
library/4.1/Rcpp/include'    -fpic  -g -O2 -fdebug-prefix-map=/build/r-
base-i2PIHO/r-base-4.1.2=. -fstack-protector-strong -Wformat -
Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -UNDEBUG -
Wall -pedantic -g -O0 -fdiagnostics-color=always -c ssc_info.cpp -o
ssc_info.o
   g++ -std=gnu++14 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -
Wl,-z,relro -o ssc.so RcppExports.o ssc_info.o -
L/opt/SAM/2020.11.29/linux_64 -lssc -L/usr/lib/R/lib -lR
   installing to /tmp/RtmpfGwydd/devtools_install_d2f4f57cbec83/00LOCK-
ssc/00new/ssc/libs
   ** checking absolute paths in shared objects and dynamic libraries
─  DONE (ssc)
Error in dyn.load(dll_copy_file) :
  unable to load shared object
'/tmp/RtmpfGwydd/pkgloadd2f4f752bdb80/ssc.so':
  ssc.so: cannot open shared object file: No such file or directory

However:
> file.exists("/tmp/RtmpfGwydd/pkgloadd2f4f752bdb80/ssc.so")
[1] TRUE

(I'm using devtools::check because R CMD check deletes the package info
after running. Also I ran Rcpp::compileAttributes() before initiating
the check.)

My sessionInfo (before running devtools::check) is:

R version 4.1.2 (2021-11-01)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 21.10

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] compiler_4.1.2

Does anybody have any suggestions? Thank you!

-Ezra



More information about the R-devel mailing list