On 02/01/2016 2:39 PM, Pierre Lafaye de Micheaux wrote:
Dear all,

Thank you very much for your answers. And sorry for the last reply.
Here is how I solved my problem.

I incorporated some files from the src/ directory of the R package
Faddeeva to
the subdirectory /libraries of the src/ directory of my own package.

I don't know of an R package called Faddeeva. There's an RcppFaddeeva package.


This is because I needed to use some functions (in C)  from this package.
Then I used something as:
#include <R.h>
#include "Rmath.h"
#include "libraries/callFaddeeva.cpp"
#include "libraries/Faddeeva.cpp"
#include "libraries/RcppExports.cpp"

It is then possible, to initialise and manipulate complex numbers in C
in my own code. For example:

cmplx I = C(0.0, 1.0); # For a + ib where a = 0 and b = 1.
cmplx res;
res = Faddeeva::erfi(I, 0.0);

And this compiles well under Windows now.

You shouldn't need to copy the code if you're using RcppFaddeeva, but I can't tell you exactly what you need to do: the Rcpp mailing list would be a better place to ask.


Note that I first tried to add the Faddeeva package in the Depends field
of my own package thinking that this might prevent me from having to put
the Faddeeva source files in my own package but it did not work ...

Depends is not the way to link at the C++ level. If this is possible, you'll need to use LinkingTo as well as Imports. I'm not sure if it's possible, but people on the Rcpp list would know...

Duncan Murdoch


Best regards,

Pierre L.




Le 13/11/2015 21:36, Duncan Murdoch a écrit :
On 13/11/2015 11:24 AM, Pierre Lafaye de Micheaux wrote:
Dear all,

I created a new version of the package IndependenceTests where I call
some C and Fortran functions (using the .C() or .Fortran() interface).
It works perfectly under Linux, with gcc. No problem with R CMD check. I
would like to upload this package on the CRAN.

But when I first tried to use winbuilder, I got an error with the
following message:

* installing *source* package 'IndependenceTests' ...
** libs

*** arch - i386
g++  -I"D:/RCompile/recent/R/include" -DNDEBUG
-I"d:/RCompile/r-compiling/local/local320/include"     -O2 -Wall
-mtune=core2 -c Cnhat.cpp -o Cnhat.o
Cnhat.cpp:9:89: error: 'complex' has not been declared
Cnhat.cpp:9:105: error: two or more data types in declaration of 'res'
....
.....
etc.


I think I understand that there is a problem (only under Windows though)
with the complex type.
The beginning of my file Cnhat.cpp is as follows:

1. #include <R.h>
2. #include "Rmath.h"
3. #include <complex.h>
4. #include <iostream>
5. using namespace std;
6.
7. extern"C" {
8.
9.   void CnhatC(double *vecs, double *vect, double *X, int *n, int *q,
int *p, int *vecd, complex double *res) {
10.
11.    void phinhatReturn(double *vect1, double *vect2, double *vect3,
double *X, int *q, int *n, double _Complex *res1, double _Complex *res2,
double _Complex *res3);
12.    double _Complex tmp2, prod1 = 1.0 + 0.0*_Complex_I, prod2 = 1.0 +
0.0*_Complex_I, somme = 0.0 + 0.0*_Complex_I;
13.    int indbeginblocl, l, i, *vecdl, k, j;
14.    double *vecsl, *mvectl, *diffvecsvectl, *Xl;
15.    double _Complex *res1, *res2, *res3;
16.    vecdl = new int[1];
17.    res1 =  new _Complex double[1];
....
.....
etc.

As you can see, there seem to be some problem (on line 9.) with: complex
double *res

Could you please point me to something (e.g., another package) that
might help me solve the problem? If possible, I would like to avoid
invest too much time using the new .Call() interface because I am quite
familiar
with the old .C(). And also I am not even sure if it would help solving
the problem.

You should be using Rcomplex in the type declaration. (See Writing R
Extensions for a discussion of this.)  It is defined as

typedef struct {
     double r;
     double i;
} Rcomplex;

which is likely compatible with your "complex double" on those other
systems (which are using newer gcc versions), but it's not guaranteed
to be, even there.

Duncan Murdoch


______________________________________________
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel

Reply via email to