Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8827341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:20:55+00:00 2026-06-14T07:20:55+00:00

I am trying to write a function in C that will be called by

  • 0

I am trying to write a function in C that will be called by R. Within it I need to take a random sample without replacement from a vector. Is it possible with Rmath.h to use something like sample() in R? If not, does anyone know why I might be getting

    Symbol not found: _gsl_rng_mt19937

When I try to dyn.load() code that calls that includes (with the appropriate headers):

      #include <gsl/gsl_randist.h>
      #include <gsl/gsl_rng.h>

     void update_infs (int *inds,
      int *inf_times,
      int *n,
      int *n_inf,
      int *locs,
      int *Rinds,
      double *logmean,
      double *logsd,
      double *alpha,
      double *wts,
      int *indices  /* a vector 1:n */
      ) { 
    ...

   /* set up GSL RNG */
   gsl_rng * rng = gsl_rng_alloc(gsl_rng_mt19937);
   /* end of GSL setup */
    ...
   gsl_ran_choose(rng, tmp_inf_me, Rinds[i], indices, *n, sizeof (double));
    ... }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:20:56+00:00Added an answer on June 14, 2026 at 7:20 am

    Likely the shared object needs to be compiled with a command like

    export PKG_CFLAGS=`gsl-config --cflags`
    export PKG_LIBS=`gsl-config --libs`
    

    and then

    R CMD SHLIB gsl.c
    

    or alternatively

    PKG_CFLAGS=`gsl-config --cflags` PKG_LIBS=`gsl-config --libs` R CMD SHLIB gsl.c
    

    This is telling the compiler where to look for headers, and the linker where to find libraries to link against. During compilation and linking the commands should contain the output of gsl-config --cflags and gsl-config --libs, along the lines of

    gcc -std=gnu99 -I/home/mtmorgan/bin/R-devel/include -I/usr/local/include -I/usr/include -fpi -c gsl.c -o gsl.o
    

    during compilatoin and

    gcc -std=gnu99 -shared -L/usr/local/lib64 -o gsl.so gsl.o -L/usr/lib -lgsl -lgslcblas -lm -L/home/mtmorgan/bin/R-devel/lib -lR
    

    during linking. A test of success is

    R -e 'dyn.load("gsl.so")'
    

    In a package one would have a file src/Makevars with

    PKG_CFLAGS = `gsl-config --cflags`
    PKG_LIBS = `gsl-config --libs`
    

    and, for Windows where gsl-config might not be available but the user has managed to install gsl and set an environment variable LIB_GSL, a file src/Makevars.win

    PKG_LIBS += -L$(LIB_GSL)$(R_ARCH)/lib -lgsl -lgslcblas -lm
    PKG_CPPFLAGS += -I$(RHOME)/src/include -I$(LIB_GSL)$(R_ARCH)/include
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a function for excel 2010 that will take a
I am trying to write a Javascript function that will be called whenever a
I am trying to write a function that will allow me to browse for
I'm trying to write a function that will: If there is no region selected,
i am trying to write a function that will make DataRow[column] return nullable typed
I'm trying to write a function that will let me red-shift or blue-shift a
I am trying to write a function that will filter a list of tuples
I am trying to write a function that will: Disable the submit button when
I am trying to write a function that will randomly return an (x,y) co-ordinates
I'm trying to write a function that will return all the available cars for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.