Re: [R] linking C/C++ external libraries.

From: Jarrod Hadfield <J.Hadfield_at_ed.ac.uk>
Date: Mon, 3 Dec 2007 17:28:12 +0000

Hi Dirk,

ldd is not bringing up csparse which suggests that it is a linking problem. For liking I used both the SHLIB and INSTALL comands using - L (see below), but both generate the same problem.

Cheers,

Jarrod

[jarrod_at_localhost ~]$ R CMD SHLIB ~/Work/AManal2/src/SStest.cc -L/ 
home/jarrod/My_Programs/SuiteSparse/CSparse/Lib -lcsparse
g++ -I/usr/lib/R/include -I/usr/lib/R/include  -I/usr/local/ 
include -fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 - fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 - march=i386 -mtune=generic -fasynchronous-unwind-tables -c /home/ jarrod/Work/AManal2/src/SStest.cc -o /home/jarrod/Work/AManal2/src/ SStest.o
/home/jarrod/Work/AManal2/src/SStest.cc: In function void SStest (int*, int*, double*, int*, int*):
/home/jarrod/Work/AManal2/src/SStest.cc:18: warning: unused variable iA
/home/jarrod/Work/AManal2/src/SStest.cc:19: warning: unused variable pA
/home/jarrod/Work/AManal2/src/SStest.cc:20: warning: unused variable xA
g++ -shared -L/usr/local/lib -o /home/jarrod/Work/AManal2/src/ SStest.so /home/jarrod/Work/AManal2/src/SStest.o -L/home/jarrod/ My_Programs/SuiteSparse/CSparse/Lib -lcsparse -L/usr/lib/R/lib -lR

 >dyn.load("~/Work/AManal2/src/SStest.so") Error in dyn.load("~/Work/AManal2/src/SStest.so") :

   unable to load shared library '/home/jarrod/Work/AManal2/src/ SStest.so':

   /home/jarrod/Work/AManal2/src/SStest.so: undefined symbol: _Z10cs_spallociiiii

[jarrod_at_localhost ~]$ R CMD INSTALL -l ~/Desktop ~/Work/AManal2 * Installing *source* package 'AManal' ...
** libs

g++ -I/usr/lib/R/include -I/usr/lib/R/include -I/home/jarrod/ My_Programs/SuiteSparse/CSparse/Include -I/usr/local/include - fpic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack- protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic - fasynchronous-unwind-tables -c SStest.cc -o SStest.o SStest.cc: In function void SStest(int*, int*, double*, int*, int*) :

SStest.cc:18: warning: unused variable iA
SStest.cc:19: warning: unused variable pA
SStest.cc:20: warning: unused variable xA
g++ -shared -L/usr/local/lib -o AManal.so SStest.o -L/home/jarrod/ My_Programs/SuiteSparse/CSparse/Lib -lcsparse -L/usr/lib/R/lib -lR
** R

library("AManal", lib.loc="~/Desktop")
Error in dyn.load(file, ...) :

   unable to load shared library '/home/jarrod/Desktop/AManal/libs/ AManal.so':

   /home/jarrod/Desktop/AManal/libs/AManal.so: undefined symbol: _Z10cs_spallociiiii
Error: package/namespace load failed for 'AManal'

On 3 Dec 2007, at 16:57, Dirk Eddelbuettel wrote:

>
> On 3 December 2007 at 14:54, Jarrod Hadfield wrote:
> | I'm trying to load some C++ code using dyn.load but I'm getting
> | unresolved symbols associated with some external libraries
> | (CSparse).  I gather this is something to do with linking as the the
> | code compiles fine.  However, I've passed
> |
> | -L/home/jarrod/My_Programs/SuiteSparse/CSparse/Lib -lcsparse
> |
> | to the complier (g++), either directly using R CMD SHLIB or as
> | PKG_LIBS in a Makevars file, and I cannot resolve the problem.  I'm
> | working with R 2.6.0 on fedora 6
> |
> | Any help would be appreciated.
>
> Can you show us your error message upon load?  What does ldd say  
> when pointed
> at your package's library?  How exactly is the linking done?
>
> Compare all that to a working library such as eg Matrix. That may  
> provide
> further clues.
>
> Hth, Dirk
>
> -- 
> Three out of two people have difficulties with fractions.
>


	[[alternative HTML version deleted]]


______________________________________________

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon 03 Dec 2007 - 17:14:43 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 03 Dec 2007 - 17:30:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.