dyn.load error linking a package with Rcpp - c++

I've made an R package with Rcpp, to use the methods of a library I programmed in c++.
I've R running on the last version:
R version 3.2.5 (2016-04-14)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04 LTS
I'm executing the following instruction to install my package:
> install.packages("mypackage", repos = NULL)
The package compiles well, I have the .o files of my source code, but in the linking phase I got the error:
* installing *source* package ‘rbdd’ ...
** libs
make: No se hace nada para 'all'.
installing to /home/sergio/R/x86_64-pc-linux-gnu-library/3.2/mypackage/libs
** R
** preparing package for lazy loading
** help
Warning: /home/sergio/R/mypackage/man/mypackage-package.Rd:27: All text must be in a section
Warning: /home/sergio/R/mypackage/man/mypackage-package.Rd:28: All text must be in a section
*** installing help indices
** building package indices
** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/home/sergio/R/x86_64-pc-linux-gnu-library/3.2/mypackage/libs/mypackage.so':
/home/sergio/R/x86_64-pc-linux-gnu-library/3.2/mypackage/libs/mypackage.so: undefined symbol: _ZN4cudd12defaultErrorENSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE
Error: loading failed
Ejecución interrumpida
ERROR: loading failed
mypackge.so is created in the src folder of my package.
I've got a Makevars file (in src, too) with the following content:
PKG_CPPFLAGS=-I./buddy-2.5/src -I./cudd-3.0.0/cudd -I./cudd-3.0.0/mtr -I./cudd-3.0.0/cplusplus -I./cudd-3.0.0/dddmp -I./cudd-3.0.0/util -I./cudd-3.0.0 -isystem /usr/include/c++/v1 -std=c++11
PKG_LIBS=-lc++ -L/lib
and my NAMESPACE file has the lines:
useDynLib(mypackage)
exportPattern("^[[:alpha:]]+")
importFrom(Rcpp, evalCpp)
Someone knows how to solve this problem?

I am a little concerned about
PKG_LIBS=-lc++ -L/lib
Did you really mean /lib? If it is your library, a more common place would be /usr/local/lib which is also search by default.
But, and that is a BIG but, you also need to understand what you need to do for ldconfig for the proper setup of libfoo.so, libfoo.so.$MAJOR and so on. I taught myself that many moons ago from a Linux HOWTO.
If and when that is setup right, you can link it to R via Rcpp. Otherwise maybe stick with system libraries, or package-local static libraries. That approach will also make your package more portable.

The problem was I am consumming external libs, and I must compile it and execute ldconfig before compile my R library.

Related

Rcpp project clean and rebuild

I'm trying to build the sample hello world file that comes by default when an Rcpp package project is created in RStudio on Mac.
I'm using latest version of RStudio (Version 1.3.959) and R (4.0.2). The clang version is 11.0.3 and have the command line tools installed.
Unlike the expected compile output of rcpp_hello_world.cpp to create .o objects I see that in my project, RStudio uses R and tries to byte-compile, avoiding the C compilation.
I also updated the Makeconf for gnu++17
(CXX = clang++ -mmacosx-version-min=10.13 -std=gnu++17)
I haev installed Rcpp, RcppEigen and BH packages and created a new Rcpp project and I updated the NAMESPACE file to recognize the Rcpp tags for interface functions.
Here is the output I got:
==> Rcpp::compileAttributes()
* Updated R/RcppExports.R
==> R CMD INSTALL --preclean --no-multiarch --with-keep.source RcppPackage003a
* installing to library ‘/Users/username/Library/R/4.0/library’
* installing *source* package ‘RcppPackage003a’ ...
** using staged installation
** R
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘RcppPackage003a’ in library.dynam(lib, package, package.lib):
shared object ‘RcppPackage003a.so’ not found
Error: loading failed
Execution halted
Any pointers on what I could be doing wrong and why it's not trying to compile the src files?
As a quick Rcpp install test I was able to call a C++ function from R (referring this doc - http://heather.cs.ucdavis.edu/Rcpp.pdf)
by sourcing a test cpp file with following function -
#include <Rcpp.h>
// [[Rcpp::export]]
void hello()
{
Rprintf("Hello, world!\n");
}
and then in R console calling the hello function after sourcing the cpp file:
library(Rcpp)
sourceCpp("hello.cpp")
hello()
How can I debug the missing link where it is not picking up the cpp file to be compiled?
Thanks in advance!

mxnet build with intel mkl always throw error "Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll."

os : windows 10 64bits
compiler : vc2015 64bits update 3
mxnet : 1.3.1
Building mxnet 1.3.1(mxnet1.4.0 has bugs, can't build it under windows,please check14203 for more details).
I can build the mxnet with cpp-package, but when I call the forward function o the Executor, it keep throwing
Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll.
Following are my steps to build the mxnet
git clone --recursive https://github.com/apache/incubator-mxnet mxnet
cd mxnet
Download intel mkl(w_mkl_2019.2.190.exe)
install it
open cmake3.11.0
I disable cpp_package,opencv,cuda,USE_MKLML_MKL(else mshadow will use openBLAS).
I disable USE_TENSORRT and USE_VTUNE too
press configure,disable BUILD_TESTING
press configure again, all green
press generate,all green
open ALL_BUILD.vcxproj
Select Release build
All build
All green, except install project fail
>file cannot create directory: C:/Program Files/mxnet/lib. Maybe need
1> administrative privileges.
Already open vc as admin, still the same error
Add Anaconda3 into PATH
Add libmxnet.dll and C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2019.2.190\windows\redist\intel64_win\mkl\mkl_rt.dll into a folder which could be found by the os
select build with cpp_package from cmake gui
configure->generate
reopen ALL_BUILD.vcxproj
Select ALL_BUILD->build
Because install do not work,I copy the files lib to build_cpu/install
Because lrs and wds of op.h do not declare type,I need to add mx_float for them
write a simple program, can compile
When I call forward of the Executor,the program throw Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll.
Add C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2019.2.190\windows\redist\intel64_win\mkl的mkl_intel_thread.dll into the folder could be found by the os
26.Run again,still the same error Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll.
My Anaconda3 install mxnet,it got mkl_intel_thread.dll and mkl_rt.dll too,I wonder there are confliction,problem is I did not add the bin path of Anaconda3 into the PATH.
I tried to copy different mkl_intel_thread.dll and mkl_rt.dll into the folder where the exe at, but every combination of them give me same error.
Those dll come from following path
C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2019.2.190\windows\redist\intel64_win\mkl
C:\Users\yyyy\Anaconda3\envs\gluon\Library\bin
C:\Users\yyyy\Anaconda3\Library\bin
C:\Users\yyyy\Anaconda3\pkgs\mkl-2019.1-144\Library\bin
Do anyone know how to solve this issue?Thanks
This problem should be caused by static MKL linkage, here's some advice may helpful to you.
Have you ever tried to set environmental variable for pre-load libs,
Here is Linux
export LD_PRELOAD=/opt/intel/mkl/lib/intel64/libmkl_def.so:/opt/intel/mkl/lib/intel64/libmkl_avx2.so:/opt/intel/mkl/lib/intel64/libmkl_core.so:/opt/intel/mkl/lib/intel64/libmkl_intel_lp64.so:/opt/intel/mkl/lib/intel64/libmkl_intel_thread.so:/opt/intel/lib/intel64_lin/libiomp5.so
In windows, setting env by mkl/bin/mklvars.bat intel64, then run your python in same environment
or in python to add the library manually sys.path.append(" your path to the library") or Pyinstaller numpy "Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll"...
If above suggestions did not help, please try to modify the 'CMakeList.txt' file, change line 44 ~ 47 to single-dynamic linkage and re-cmake to install:
if(MSVC)
set(LIBS ${LIBS} mkl_rt ${MKL_COMPILER_LIB_FILE} PARENT_SCOPE)
else()
set(LIBS ${LIBS} mkl_rt ${MKL_COMPILER_LIB_FILE} PARENT_SCOPE)

R: Error in dyn.load(file, DLLpath = DLLpath, ...)

I have worked now for some time on an R project in my office's desktop computer, but need to carry the scripts with me while on travel. I copied everything into my laptop and did some changes to the code. Alas, when trying to compile (following the exact same procedure I was using in my desktop computer), the following error:
$ R CMD INSTALL --no-multiarch --with-keep.source coala
* installing to library ‘/home/my_pc/R/x86_64-pc-linux-gnu-library/3.3’
* installing *source* package ‘coala’ ...
** libs
make: Nothing to be done for `all'.
installing to /home/my_pc/R/x86_64-pc-linux-gnu-library/3.3/coala/libs
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/home/my_pc/R/x86_64-pc-linux-gnu-library/3.3/coala/libs/coala.so':
/home/my_pc/R/x86_64-pc-linux-gnu-library/3.3/coala/libs/coala.so: undefined symbol: _ZSt24__throw_out_of_range_fmtPKcz
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/my_pc/R/x86_64-pc-linux-gnu-library/3.3/coala’
* restoring previous ‘/home/my_pc/R/x86_64-pc-linux-gnu-library/3.3/coala’
Both computers have the same Ubuntu but different R version. Also, I have to mention that I am working in two libraries at the same time and that the accompanying library update without problems, which makes this error message more puzzling. I have checked answers that may be related to this question, but can't figure out how to apply their solutions:
R: error installing packages UBUNTU - Error in dyn.load(file, DLLpath = DLLpath, ...) : unable to load shared object
Got message unable to load shared object stats.so when R starts
Is there a way to solve this problem? Which may be the cause? What is the undefined symbol _ZSt24__throw_out_of_range_fmtPKcz?
I had a similar issue with rgdal on Ubuntu. Re-installing the package was enough to getting it working again.
$ sudo R
> install.packages("rgdal")
> quit()
$ exit
What is .libPaths() giving you as the output?
I encountered the same problem using the latest update today (R 3.3.1 for MacOS X). My R installation seemed to crash after updating it. My solution was simply to remove the lib directories from the file system and reinstall R:
rm -rf /Users/johann/Library/R/3.3/library
sudo rm -rf Library/Frameworks/R.framework/Versions/3.3/Resources/library
Hope this helps...
The problem is the linkage with your g++ stdlib. Different versions of Ubuntu have different versions of g++ stdlib. You cant always copy binaries from one to the other.
You may fix this by recompiling R for the laptop, or using the Ubuntu R packages. e.g. http://packages.ubuntu.com/xenial/r-base
For Mac / Linux
Press command + space
Type terminal and press enter to open terminal. In terminal paste this open /Library/Frameworks/R.framework/Resources/library and press enter. A finder window should open with a lot of folders
Each folder matches an installed R package.
Delete them all, close RStudio, reopen RStudio and install the packages you need with install.packages("dplyr") etc
After I did this, the issue went away

Compilation of OpenCV / Eigen3 fail

I want to use OpenCV but I cannot compile it and I think It's because of Eigen.
when I use Cmake command, Eigen is found:
> -- Use Eigen: YES (ver 3.2.2)
Whereas I have only Eigen2 on my computer. (Maybe It's an obsolete file but I don't know where it comes from).
Then, once Cmake is done I do
make -j4
At 64% I have this following error:
/home/sl001093/opencv-2.4.10/modules/contrib/src/rgbdodometry.cpp:65:47: fatal error: unsupported/Eigen/MatrixFunctions : no file like that
compilation aborted.
make[2]: * [modules/contrib/CMakeFiles/opencv_contrib.dir/src/rgbdodometry.cpp.o] Error 1
make1: * [modules/contrib/CMakeFiles/opencv_contrib.dir/all] Error 2
make: *** [all] Erreur 2
Thank you very much in advance !
EDIT: here the output of the command line ccmake
Use cmake-gui
Set OpenCV source and build directory
Configure
In the Search box, type "eigen"
Activate "WITH_EIGEN" flag
Configure again
A variable "EIGEN_INCLUDE_PATH" should appear: click there and browse to the "include" subdirectory of your Eigen library.
Eigen is a header only library, so you don't need to install/build it: just download a package (see "Get it" section on the right side of the page) and unzip it for the purpose of building OpenCV.
BTW, why are you using OpenCV 2.4 when there is already OpenCV 3 available? It might be that OpenCV 2.4 is not compatible with recent versions of Eigen, but I know as a fact that it is compatible with version 3.2.2.

ocaml-glpk (glpk bindings) and OASIS

Preface: I am new to OCaml, OPAM, and OASIS.
tldr question: How do I properly set up a package with opam that is not already available in the repository (I can't just do opam install X)? More details follow:
I am trying to include ocaml-glpk in an OCaml project. I installed ocaml-glpk just by running make and make install as stated in the README, and the given example compiles and runs correctly. However, I am using OASIS to generate the build system of my project, and I am not sure how to set it up. I have the same example (renamed to glpkExample.ml in a src folder) and the following in my _oasis file:
Executable "glpkExample"
Path: src
MainIs: glpkExample.ml
CompiledObject: best
BuildDepends:
glpk
After running oasis setup -setup-update dynamic, I run make and get the following error:
ocaml setup.ml -build
Finished, 0 targets (0 cached) in 00:00:00.
+ /home/dimitrios/.opam/system/bin/ocamlfind ocamlopt -g -linkpkg -package glpk src/glpkExample.cmx -o src/glpkExample.native
File "_none_", line 1:
Error: Cannot find file /home/dimitrios/.opam/system/lib/glpk/glpk.cmxa
Command exited with code 2.
Compilation unsuccessful after building 4 targets (3 cached) in 00:00:00.
E: Failure("Command ''/usr/bin/ocamlbuild' src/glpkExample.native -tag debug' terminated with error code 10")
make: *** [build] Error 1
It seems the glpk library is missing a cmxa file needed to compile a native executable. I am not sure how to fix this. To compile glpkExample.ml correctly, my Makefile includes /home/dimitrios/.opam/system/lib/glpk and also uses the OCamlMakefile, which is extremely long and convoluted. Any help on setting this up with OASIS or how to get ocaml-glpk to work nicely with OASIS would be greatly appreciated.
Thanks!
This website is not appropriate for bug reports. You should really report it here.
The temporary solution is to use CompiledObject: byte to compile in bytecode.
If you're using opam then it is best to install application with it, not manually. Try to clean up your system and remove whatever you installed, and then do:
$ eval `opam config env`
$ opam install ocaml-glpk
Afterwards, if glpk is packaged in opam correctly, it should work with your setup, i.e., just with oasis's BuildDepends field and nothing more.