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

From: Jarrod Hadfield <>
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.



[jarrod_at_localhost ~]$ R CMD SHLIB ~/Work/AManal2/src/ -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/ -o /home/jarrod/Work/AManal2/src/ SStest.o
/home/jarrod/Work/AManal2/src/ In function void SStest (int*, int*, double*, int*, int*):
/home/jarrod/Work/AManal2/src/ warning: unused variable iA
/home/jarrod/Work/AManal2/src/ warning: unused variable pA
/home/jarrod/Work/AManal2/src/ warning: unused variable xA
g++ -shared -L/usr/local/lib -o /home/jarrod/Work/AManal2/src/ /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/") Error in dyn.load("~/Work/AManal2/src/") :

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

   /home/jarrod/Work/AManal2/src/ 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 -o SStest.o In function void SStest(int*, int*, double*, int*, int*) : warning: unused variable iA warning: unused variable pA warning: unused variable xA
g++ -shared -L/usr/local/lib -o 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/':

   /home/jarrod/Desktop/AManal/libs/ 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]]

______________________________________________ mailing list PLEASE do read the posting guide 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 Please read the posting guide before posting to the list.