I've built a package for interacting with HDFql from R. It relies on the R wrapper and DLLs/SOs provided by HDFql 2.1.0. The packages works perfectly in Windows using the DLLs, but for some reason the HDFql library SOs fail to load in a Linux environment. I've tried this both on Travis and on a local Docker Linux/R container.
The relevant code contained in the function hql_load()
is below. Assume that HDFql is extracted to a folder in the current directory "/hdfql-2.1.0", which means that
dllpath = c("/hdfql-2.1.0/lib/libHDFql.so", "/hdfql-2.1.0/wrapper/R/libHDFqlR.so")
I check that these paths exist using normalizePath(dllpath, mustWork = TRUE)
and also check that the objects load successfully and appear in getLoadedDlls()
.
# ... starting at line 153 of connect.r ... #
wrapper.file = tempfile(fileext = ".r")
wrapper.lines = readLines(wrapperpath)
writeLines(wrapper.lines[-grep("dyn\\.load", wrapper.lines)],
wrapper.file)
# load DLLs
for (dll in dllpath) {
dyn.load(dll, local = FALSE, now = TRUE)
if (!dll %in% sapply(getLoadedDLLs(), function(x) normalizePath(x[["path"]], mustWork = FALSE))) {
stop("Error loading HDFql shared library object ", dll)
}
}
# load wrapper
wrapper = new.env(parent = .BaseNamespaceEnv)
tryCatch(
sys.source(wrapper.file, envir = wrapper, toplevel.env = packageName()),
error = function(e) {
stop("Failed to execute HDFql R wrapper.\n Additional Information:\n",
e)
}
)
assign("wrapper", wrapper, envir = hql)
invisible(NULL)
}
The error occurs in the sys.source
call to evaluate the code in the wrapper file provided by HDFql, and specifically in the initialization call. The wrapper contents are below; note that in my function above I remove the dyn.load
calls from the wrapper before evaluating it (the libraries are loaded beforehand).
hdfql_operating_system = Sys.info()["sysname"]
if (hdfql_operating_system == "Windows")
{
dyn.load("HDFqlR.dll")
hdfql_shared_library <- "HDFqlR"
} else if (hdfql_operating_system == "Linux")
{
dyn.load("libHDFqlR.so")
hdfql_shared_library <- "libHDFqlR"
} else # macOS
{
dyn.load("libHDFqlR.dylib")
hdfql_shared_library <- "libHDFqlR.dylib"
}
rm(hdfql_operating_system)
#===========================================================
# INITIALIZE HDFQL R WRAPPER SHARED LIBRARY
#===========================================================
hdfql_initialize_status = .Call("_hdfql_initialize", PACKAGE = hdfql_shared_library)
Error: Failed to execute HDFql R wrapper.
Additional Information:
Error in eval(parse(wrapper.file), envir = wrapper): Could not find/load HDFql shared library 'libHDFql.so'!
I have been troubleshooting this for weeks with little progress. Can anyone tell me why the library is not loading correctly in Linux systems?