Hi all,
I have a C++ application I developed, with its headers (.hpp) and
related .cpp files. Within this project I use a templated header-only
library for efficient parallel computing using pthreads, as well as the
GSL library.
My intent is to use this application within a R package, and I use
RStudio under GNU Linux to create an Rcpp package.
I created a c++ function with '[[Rcpp::export]]' attribute that includes
headers of my project and wraps a sort of entry point to the
application. Something like:
#include "cppApp.hpp"
// [[Rcpp::export]]
int wrapApp(Args...) {
// set up parameters
runParallelCppApp(Params...);
return 0;
}
I carefully edited the DESCRIPTION file with lines
LinkingTo: Rcpp, RcppGSL
SystemRequirements: C++11
While the Makevars file contains:
PKG_CPPFLAGS = -DPRINTLOG -I"../inst/include" -pthread
PKG_LIBS = -lcurl -lpthread `$(R_HOME)/bin/Rscript -e \
"Rcpp:::LdFlags()"` $(R_HOME)/bin/Rscript -e "RcppGSL:::LdFlags()"`
CXX_STD = CXX11
Everything compiles fine, but then it fails when loading the package:
** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object
'/home/fabio/R/x86_64-pc-linux-gnu-library/3.0/NgrapH/libs/NgrapH.so':
/home/fabio/R/x86_64-pc-linux-gnu-library/3.0/NgrapH/libs/NgrapH.so:
undefined symbol: _ZN6Finder10parseFilesESsSsSs
Error: loading failed
What could possibly be the problem?
Thanks in advance,
Fabio
[Rcpp-devel] loading failed
9 messages · Fabio Tordini, Kevin Ushey, Dirk Eddelbuettel
On 5 May 2015 at 14:30, Fabio Tordini wrote:
| Everything compiles fine, but then it fails when loading the package: | | ** testing if installed package can be loaded | Error in dyn.load(file, DLLpath = DLLpath, ...) : | unable to load shared object | '/home/fabio/R/x86_64-pc-linux-gnu-library/3.0/NgrapH/libs/NgrapH.so': | /home/fabio/R/x86_64-pc-linux-gnu-library/3.0/NgrapH/libs/NgrapH.so: | undefined symbol: _ZN6Finder10parseFilesESsSsSs | Error: loading failed | | What could possibly be the problem? edd at max:~$ c++filt _ZN6Finder10parseFilesESsSsSs Finder::parseFiles(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >) edd at max:~$ You seem to instantiate Finder::parseFiles without providing (object) code for it. As you example is incomplete and irreproducible we can only guess. Maybe you forgot to link to another library. Maybe you forgot a source file. Dirk
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
Hi Dirk, thanks for your reply!
On 05/05/2015 04:14 PM, Dirk Eddelbuettel wrote:
On 5 May 2015 at 14:30, Fabio Tordini wrote: | Everything compiles fine, but then it fails when loading the package: | | ** testing if installed package can be loaded | Error in dyn.load(file, DLLpath = DLLpath, ...) : | unable to load shared object | '/home/fabio/R/x86_64-pc-linux-gnu-library/3.0/NgrapH/libs/NgrapH.so': | /home/fabio/R/x86_64-pc-linux-gnu-library/3.0/NgrapH/libs/NgrapH.so: | undefined symbol: _ZN6Finder10parseFilesESsSsSs | Error: loading failed | | What could possibly be the problem? edd at max:~$ c++filt _ZN6Finder10parseFilesESsSsSs Finder::parseFiles(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >) edd at max:~$
Yep, I used c++filt as well and found out the exact function. But still I can't figure out the problem. Here is the actual (simple) code: Finder *f = new Finder(); f->parseFiles(str_g, str_f, str_s); where the three strings contain path-to-files. What do you exactly mean with "...without providing (object) code for it"?
You seem to instantiate Finder::parseFiles without providing (object) code for it. As you example is incomplete and irreproducible we can only guess. Maybe you forgot to link to another library. Maybe you forgot a source file.
No other libraries needed, no source file missing: the Makevars file somehow resembles application's Makefile!
Dirk
Fabio
On 5 May 2015 at 16:28, Fabio Tordini wrote:
| Here is the actual (simple) code: | | Finder *f = new Finder(); | f->parseFiles(str_g, str_f, str_s); So where is Finder implemented? The computer tells you that you want to use it, but don't supply it. Dirk
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
Ok, I found the 'scrm' Rcpp package: here the file scrmr.cpp provides an interface for calling the scrm C++ application from R. following their solution, I modified my Makevars file, adding: OBJECTS.PnuChart = ngraph.o RcppExports.o OBJECTS.PnuChart = PnuChart/Finder.o OBJECTS = $(OBJECTS.PnuChart) Now the linker finds the object files and knows where functions "are". so, previous error is solved. but loading still fails with the following message: /home/fabio/R/x86_64-pc-linux-gnu-library/3.0/NgrapH/libs/NgrapH.so: undefined symbol: gsl_vector_alloc Error: loading failed In fact, I do use gsl, that's why I added RcppGSL in the DESCRIPTION file at 'LinkingTo'. Also, I use the attribute '// [[Rcpp::depends(RcppGSL)]]' in those headers where GSL functions are used, and included <RcppGSL.h>. I do not export those functions because they're not called directly from R. still, I get the loading failed error. Fabio
On 05/05/2015 10:15 PM, Dirk Eddelbuettel wrote:
On 5 May 2015 at 16:28, Fabio Tordini wrote: | Here is the actual (simple) code: | | Finder *f = new Finder(); | f->parseFiles(str_g, str_f, str_s); So where is Finder implemented? The computer tells you that you want to use it, but don't supply it. Dirk
You need to link to GSL as well. RcppGSL provides the appropriate flags within `RcppGSL::LdFlags()`. See what RcppGSL does itself in its configure scripts: https://github.com/eddelbuettel/rcppgsl/blob/2849b8dd777c8057e524c2141dfeaa8e28840350/inst/skeleton/configure.win . Kevin
On Tue, May 5, 2015 at 2:08 PM, Fabio Tordini <tordini at di.unito.it> wrote:
Ok, I found the 'scrm' Rcpp package: here the file scrmr.cpp provides an interface for calling the scrm C++ application from R. following their solution, I modified my Makevars file, adding: OBJECTS.PnuChart = ngraph.o RcppExports.o OBJECTS.PnuChart = PnuChart/Finder.o OBJECTS = $(OBJECTS.PnuChart) Now the linker finds the object files and knows where functions "are". so, previous error is solved. but loading still fails with the following message: /home/fabio/R/x86_64-pc-linux-gnu-library/3.0/NgrapH/libs/NgrapH.so: undefined symbol: gsl_vector_alloc Error: loading failed In fact, I do use gsl, that's why I added RcppGSL in the DESCRIPTION file at 'LinkingTo'. Also, I use the attribute '// [[Rcpp::depends(RcppGSL)]]' in those headers where GSL functions are used, and included <RcppGSL.h>. I do not export those functions because they're not called directly from R. still, I get the loading failed error. Fabio On 05/05/2015 10:15 PM, Dirk Eddelbuettel wrote:
On 5 May 2015 at 16:28, Fabio Tordini wrote: | Here is the actual (simple) code: | | Finder *f = new Finder(); | f->parseFiles(str_g, str_f, str_s); So where is Finder implemented? The computer tells you that you want to use it, but don't supply it. Dirk
_______________________________________________
Rcpp-devel mailing list Rcpp-devel at lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20150505/c43bdbc2/attachment.html>
Done already, without success. The whole Makevars file is as follows (I didnt paste it before): OBJECTS.PnuChart = ngraph.o RcppExports.o OBJECTS.PnuChart = PnuChart/Finder.o OBJECTS = $(OBJECTS.PnuChart) PKG_CPPFLAGS = -DPRINTLOG -I"../inst/include" -I. -pthread PKG_LIBS = -lcurl -lpthread `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"` $(R_HOME)/bin/Rscript -e "RcppGSL:::LdFlags()"` CXX_STD = CXX11 And the g++ linking phase: g++ -std=c++0x -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o NgrapH.so PnuChart/Finder.o -lcurl -lpthread /usr/lib/R/bin/Rscript -e RcppGSL:::LdFlags()/usr/lib/R/bin/Rscript -e Rcpp:::LdFlags()-L/usr/lib -lgsl -lgslcblas -lm -L/usr/lib/R/lib -lR Fabio
On 05/05/2015 11:14 PM, Kevin Ushey wrote:
You need to link to GSL as well. RcppGSL provides the appropriate flags within `RcppGSL::LdFlags()`. See what RcppGSL does itself in its configure scripts: https://github.com/eddelbuettel/rcppgsl/blob/2849b8dd777c8057e524c2141dfeaa8e28840350/inst/skeleton/configure.win. Kevin On Tue, May 5, 2015 at 2:08 PM, Fabio Tordini <tordini at di.unito.it <mailto:tordini at di.unito.it>> wrote: Ok, I found the 'scrm' Rcpp package: here the file scrmr.cpp provides an interface for calling the scrm C++ application from R. following their solution, I modified my Makevars file, adding: OBJECTS.PnuChart = ngraph.o RcppExports.o OBJECTS.PnuChart = PnuChart/Finder.o OBJECTS = $(OBJECTS.PnuChart) Now the linker finds the object files and knows where functions "are". so, previous error is solved. but loading still fails with the following message: /home/fabio/R/x86_64-pc-linux-gnu-library/3.0/NgrapH/libs/NgrapH.so: undefined symbol: gsl_vector_alloc Error: loading failed In fact, I do use gsl, that's why I added RcppGSL in the DESCRIPTION file at 'LinkingTo'. Also, I use the attribute '// [[Rcpp::depends(RcppGSL)]]' in those headers where GSL functions are used, and included <RcppGSL.h>. I do not export those functions because they're not called directly from R. still, I get the loading failed error. Fabio On 05/05/2015 10:15 PM, Dirk Eddelbuettel wrote: On 5 May 2015 at 16:28, Fabio Tordini wrote: | Here is the actual (simple) code: | | Finder *f = new Finder(); | f->parseFiles(str_g, str_f, str_s); So where is Finder implemented? The computer tells you that you want to use it, but don't supply it. Dirk
_______________________________________________
Rcpp-devel mailing list
Rcpp-devel at lists.r-forge.r-project.org
<mailto:Rcpp-devel at lists.r-forge.r-project.org>
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Fabio Tordini PhD Candidate Computer Science Dep. University of Torino - Italy
Fabio, The RcppGSL package ships its own example package: edd at max:~$ cd /tmp/ edd at max:/tmp$ cp -vax /usr/local/lib/R/site-library/RcppGSL/examples/RcppGSLExample/ . ?/usr/local/lib/R/site-library/RcppGSL/examples/RcppGSLExample/? -> ?./RcppGSLExample? ?/usr/local/lib/R/site-library/RcppGSL/examples/RcppGSLExample/R? -> ?./RcppGSLExample/R? ?/usr/local/lib/R/site-library/RcppGSL/examples/RcppGSLExample/R/colNorm.R? -> ?./RcppGSLExample/R/colNorm.R? ?/usr/local/lib/R/site-library/RcppGSL/examples/RcppGSLExample/man? -> ?./RcppGSLExample/man? ?/usr/local/lib/R/site-library/RcppGSL/examples/RcppGSLExample/man/colNorm.Rd? -> ?./RcppGSLExample/man/colNorm.Rd? ?/usr/local/lib/R/site-library/RcppGSL/examples/RcppGSLExample/src? -> ?./RcppGSLExample/src? ?/usr/local/lib/R/site-library/RcppGSL/examples/RcppGSLExample/src/Makevars.in? -> ?./RcppGSLExample/src/Makevars.in? ?/usr/local/lib/R/site-library/RcppGSL/examples/RcppGSLExample/src/Makevars.win? -> ?./RcppGSLExample/src/Makevars.win? ?/usr/local/lib/R/site-library/RcppGSL/examples/RcppGSLExample/src/colNorm.cpp? -> ?./RcppGSLExample/src/colNorm.cpp? ?/usr/local/lib/R/site-library/RcppGSL/examples/RcppGSLExample/DESCRIPTION? -> ?./RcppGSLExample/DESCRIPTION? ?/usr/local/lib/R/site-library/RcppGSL/examples/RcppGSLExample/NAMESPACE? -> ?./RcppGSLExample/NAMESPACE? ?/usr/local/lib/R/site-library/RcppGSL/examples/RcppGSLExample/configure? -> ?./RcppGSLExample/configure? ?/usr/local/lib/R/site-library/RcppGSL/examples/RcppGSLExample/configure.ac? -> ?./RcppGSLExample/configure.ac? edd at max:/tmp$ R CMD build RcppGSLExample * checking for file ?RcppGSLExample/DESCRIPTION? ... OK * preparing ?RcppGSLExample?: * checking DESCRIPTION meta-information ... OK * cleaning src * checking for LF line-endings in source and make files * checking for empty or unneeded directories * building ?RcppGSLExample_0.0.2.tar.gz? edd at max:/tmp$ R CMD check RcppGSLExample_0.0.2.tar.gz * using log directory ?/tmp/RcppGSLExample.Rcheck? * using R version 3.2.0 (2015-04-16) * using platform: x86_64-pc-linux-gnu (64-bit) * using session charset: UTF-8 * checking for file ?RcppGSLExample/DESCRIPTION? ... OK * this is package ?RcppGSLExample? version ?0.0.2? * checking package namespace information ... OK * checking package dependencies ... OK * checking if this is a source package ... OK * checking if there is a namespace ... OK * checking for executable files ... OK * checking for hidden files and directories ... OK * checking for portable file names ... OK * checking for sufficient/correct file permissions ... OK * checking whether package ?RcppGSLExample? can be installed ... OK * checking installed package size ... OK * checking package directory ... OK * checking DESCRIPTION meta-information ... NOTE Malformed Description field: should contain one or more complete sentences. * checking top-level files ... OK * checking for left-over files ... OK * checking index information ... OK * checking package subdirectories ... OK * checking R files for non-ASCII characters ... OK * checking R files for syntax errors ... OK * checking whether the package can be loaded ... OK * checking whether the package can be loaded with stated dependencies ... OK * checking whether the package can be unloaded cleanly ... OK * checking whether the namespace can be loaded with stated dependencies ... OK * checking whether the namespace can be unloaded cleanly ... OK * checking loading without being on the library search path ... OK * checking dependencies in R code ... OK * checking S3 generic/method consistency ... OK * checking replacement functions ... OK * checking foreign function calls ... OK * checking R code for possible problems ... OK * checking Rd files ... OK * checking Rd metadata ... OK * checking Rd cross-references ... OK * checking for missing documentation entries ... OK * checking for code/documentation mismatches ... OK * checking Rd \usage sections ... OK * checking Rd contents ... OK * checking for unstated dependencies in examples ... OK * checking line endings in C/C++/Fortran sources/headers ... OK * checking line endings in Makefiles ... OK * checking compilation flags in Makevars ... OK * checking for GNU extensions in Makefiles ... OK * checking for portable use of $(BLAS_LIBS) and $(LAPACK_LIBS) ... OK * checking compiled code ... OK * checking examples ... OK * checking PDF version of manual ... OK * DONE Status: 1 NOTE See ?/tmp/RcppGSLExample.Rcheck/00check.log? for details. edd at max:/tmp$ Apart from one NOTE due to changing R CMD check standards, this works. Start from there. Try to understand what it does. Then add your code. Dirk
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
It works! I used the configure.ac script to re-generate proper Makevars. The tricky point is that I had to manually add directives to object files and hide the config script, otherwise the Makevars file gets rewritten when rebuilding. I feel like there must be some more elegant way to do it... thanks a lot! Now it's time to start playing with Rcpp Sugar! Fabio
Apart from one NOTE due to changing R CMD check standards, this works. Start from there. Try to understand what it does. Then add your code. Dirk