[m-users.] Error with static linking for the rmath library

Mark Clements mark.clements at ki.se
Sat Feb 11 22:30:30 AEDT 2023


For the rmath library in Mercury (https://github.com/mclements/mercury-rmath), I am trying to use C code for the Mersenne Twister random number generator to replace the default random number generator. This involves replacing two C functions: double unif_rand(void) and void set_seed(unsigned int, unsigned int); for details, see https://rstudio.github.io/r-manuals/r-admin/The-standalone-Rmath-library.html.

I have got this working -- _except_ if any of four functions (dwilcox, pwilcox, qwilcox, rwilcox) are included in the interface section (see the gist at https://gist.github.com/mclements/68aa486f6ef4cfc9634076dad357e483). I then get a linking error (make minimal_fails):

/usr/bin/ld: /usr/lib/libRmath.a(std_unif.o): in function `set_seed':
(.text+0x0): multiple definition of `set_seed'; Mercury/os/minimal_fails.o:minimal_fails.c:(.text+0xb0): first defined here
/usr/bin/ld: /usr/lib/libRmath.a(std_unif.o): in function `unif_rand':
(.text+0x40): multiple definition of `unif_rand'; Mercury/os/minimal_fails.o:minimal_fails.c:(.text+0xc0): first defined here

If I move those functions to the implementation section, then the linking is okay (make minimal_ok).

Can anyone suggest why this fails and then works?

Sincerely, Mark.


När du skickar e-post till Karolinska Institutet (KI) innebär detta att KI kommer att behandla dina personuppgifter. Här finns information om hur KI behandlar personuppgifter<https://ki.se/medarbetare/integritetsskyddspolicy>.


Sending email to Karolinska Institutet (KI) will result in KI processing your personal data. You can read more about KI’s processing of personal data here<https://ki.se/en/staff/data-protection-policy>.


More information about the users mailing list