How to compile Phobos with other D code to create a shared library?

bachmeier no at spam.net
Fri Jun 4 15:19:17 UTC 2021


On Friday, 4 June 2021 at 07:26:53 UTC, data pulverizer wrote:

> Thanks. Looks like I have some more reading to do. I did know 
> about embedr, but I saw it had dependencies and I wanted a 
> standalone and fully transparent D solution.

It requires an R package if you want to call D functions from R. 
You need to link to R itself if you want to do something like 
pass a vector from R to D and then access that data from D. Since 
R is aware of the location of all the underlying libraries, it's 
easiest to let it generate the dub.sdl for you.

I guess you're using the older .C interface [as done 
here](http://users.stat.umn.edu/~geyer/rc/). Good enough if 
passing double* and int* pointers to D functions will suffice. 
Only thing you need to do to initialize the D runtime is add this 
to your D code

```
struct DllInfo;

extern(C) void R_init_libfoo(DllInfo * info) {
     Runtime.initialize();
}
```

where foo is the name of the library you're loading (foo.so).


More information about the Digitalmars-d-learn mailing list