Why are extern(C/C++) definitions and references mangled differently in separately compiled modules?

Stefan Koch uplink.coder at googlemail.com
Fri Sep 6 15:52:46 UTC 2019


On Friday, 6 September 2019 at 15:09:22 UTC, Max Samukha wrote:
> Consider the following two modules:
>
> 1. test.d:
>
> module test;
>
> import lib.a;
>
> void main() {
>     foo();
> }
>
>
> 2. lib/a.d:
>
> module lib.a;
>
> extern(C) void foo() {}
>
>
> When compiled separately (dmd -c lib/a.d; dmd test.d a.o), the 
> function in 'a.o' is mangled as 'foo', but the reference in 
> 'test.o' is mangled as '_D3lib1a3fooFZv', which leads to a link 
> error. I would expect both of them to be either plain C 
> mangling, or fully qualified D (better). What is the reason for 
> current behavior?

If that is happening you hit a bug.
It seems unlikely though.


More information about the Digitalmars-d-learn mailing list