[R] include C functions from nmath in my own C functions

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Aug 11 09:19:13 CEST 2005


First, please read the posting guide: it says C programming questions 
should go to R-devel so it seems you have not done so.

Second, you have not told us your OS nor what you did to run your code, so 
we have to guess. But sin etc are not 'R functions' but C mathematical 
functions, and the quess is that you failed to link against libm.  Most C 
compilers will do that for you automatically or do not even have a 
separate libm, so telling us your OS (as the posting guide does ask) was 
important.

Please seek local C programming help on how to do this on your OS.

On Wed, 10 Aug 2005, yyan liu wrote:

> Hi:
>  I followed the README in src/nmath/standalone/
> to make the use the command "make shared" to make the
> libRmath.so file. I also add the directories containg
> libRmath.so to  LD_LIBRARY_PATH by using command
> "export
> LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$/home/zhliu/Backup/R-2.0.1/src/nmath/standalon
>    e
> "
> However, when I try to run the following codes.
> /***********************************************/
> #define MATHLIB_STANDALONE 1
> #include <Rmath.h>
>
> int
> main()
> {
> /* something to force the library to be included */
>    qnorm(0.7, 0.0, 1.0, 0, 0);
>    return 0;
> }
> /**************************************************/
>
> It gives me the following error message. It seems
> definitions of some R functions can not be found in
> the libRmath.so file. Anyone has any idea about this
> problem? Thank you very much!
>
>
> /usr/local/lib/libRmath.so: undefined reference to
> `expm1'
> /usr/local/lib/libRmath.so: undefined reference to
> `log'
> /usr/local/lib/libRmath.so: undefined reference to
> `sqrt'
> /usr/local/lib/libRmath.so: undefined reference to
> `rint'
> /usr/local/lib/libRmath.so: undefined reference to
> `cos'
> /usr/local/lib/libRmath.so: undefined reference to
> `sin'
> /usr/local/lib/libRmath.so: undefined reference to
> `pow'
> /usr/local/lib/libRmath.so: undefined reference to
> `sinh'
> /usr/local/lib/libRmath.so: undefined reference to
> `log10'
> /usr/local/lib/libRmath.so: undefined reference to
> `exp'
> /usr/local/lib/libRmath.so: undefined reference to
> `tan'
> /usr/local/lib/libRmath.so: undefined reference to
> `log1p'
> /usr/local/lib/libRmath.so: undefined reference to
> `hypot'
> collect2: ld returned 1 exit status
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list