I am trying to use the R API to call optim functions (nmmin, vmmin, lbfgsb,
etc.) through a C program but I couldn't find the shared library to link
under the R-2.6.0 build which is compiled under Linux (REL5).

main.cpp:35: undefined reference to `Rf_initEmbeddedR(int, char**)'
main.cpp:41: undefined reference to `nmmin'

Thanks in advance for any help.

------------------------
#include <R_ext/Applic.h>
#include <R.h>
#include <stdio.h>

double parabola(int n, double *par, void *ex) {   double xm = par[0] - 1;
  return xm * xm + 13;
}

/*
 * Copied from tests/Embedded/embeddedRCall.c:
 */


extern int Rf_initEmbeddedR(int argc, char *argv[]);
int main()
{
  char *argv[]= {"nmminDemo", "--gui=none", "--silent"};   const int argc =
3;

  double initial[1] = {1.5};
  double result[1];
  double value;
  int convergenceCode;

  /*
   * The following values are based on the help
   * page for optim.
   */


  const double abstol = 1e-16;
  const double reltol = 1e-8;
  const double alpha = 1.0; /* reflection factor */   const double beta =
0.5; /* contraction factor */   const double gamm = 2.0; /* expansion factor
*/   const int trace = 0; /* tracing on */
  int fncount;
  const int maxit = 10000;
  Rf_initEmbeddedR(argc, argv);

  nmmin(1, initial, result, &value, parabola,

        &convergenceCode, abstol, reltol,
        NULL, alpha, beta, gamm,
        trace, &fncount, maxit);
  printf("fncount: %d\n", fncount);

  printf("convergence code: %d\n", convergenceCode);   printf("min of %f at
x = %f\n", value, result[0]);   return 0;
}

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to