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

Max Samukha maxsamukha at gmail.com
Fri Sep 6 15:09:22 UTC 2019

Consider the following two modules:

1. test.d:

module test;

import lib.a;

void main() {

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 

More information about the Digitalmars-d-learn mailing list