Using C++ Classes From D: dmd cannot link, while ldc segfault

mw mingwu at gmail.com
Mon Jun 19 06:11:59 UTC 2023


On Monday, 19 June 2023 at 05:56:54 UTC, Richard (Rikki) Andrew 
Cattermole wrote:
> On 19/06/2023 5:54 PM, mw wrote:
>> Ha, I saw vector.d there, So I can use this vector.d as the D 
>> side of C++'s std::vector?
>
> Probably, I just don't know how well tested it is.
>
> But worth a go!

```
import core.stdcpp.vector;

extern(C++) {

void getInts(core.stdcpp.vector.vector!(int) vec) {
   foreach (int i; 0 .. 10) {
     vec.push_back(i);
   }
}

}
```

dmd v2.104.0 failed:

```
/usr/include/dmd/druntime/import/core/stdcpp/vector.d(58): Error: 
undefined identifier `size`, did you mean alias `size_t`?
/usr/include/dmd/druntime/import/core/stdcpp/vector.d(33): Error: 
template instance `core.stdcpp.vector.vector!(int, 
allocator!int)` error instantiating
main.d(32):        instantiated from here: `vector!int`
```

LDC - the LLVM D compiler (1.32.2):
```
main.d(32): Error: undefined identifier `vector` in module 
`core.stdcpp.vector`, did you mean enum member `MIctor`?
```

So what's wrong the LDC? how do I write 
`core.stdcpp.vector.vector` then?


More information about the Digitalmars-d-learn mailing list