On Tuesday, 22 October 2024 at 12:44:22 UTC, Maximilian Naderer wrote:
Dear community,
I want to create a library which is usable from C and D.
D should be a first class citizen and C because of FFI for other languages.
The lib is compiled with -betterC

Because C does not have namespaces i want to add the prefix of the lib like "leogfx" but in D i don't want that because we don't need this.


extern(C):

private {
    bool pInit() {
        return true;
    }
}


pragma mangle modifies how the symbol name will appear to the linker.


```d
pragma(mangle, "leogfx_init")
bool pInit() {
...
}
```

additionally IIRC you can even loop it on itself to self modify it, at least I remember doing something like this to keep its name consistent on code refactoring.

```d
pragma(mangle, "leogfx_" ~ __traits(identifier, pInit))
bool pInit() {
...
}
```

Reply via email to