digitalmars.D.learn - C++ namespace mangling: bug or me being stupid?
- Atila Neves (48/48) Mar 28 2017 I'm trying to wrap a C++ library and have reduced my problem case
- kinke (5/8) Mar 28 2017 That's a mangling compression scheme (possibly tunable via gcc
- Atila Neves (3/11) Mar 28 2017 Good to know, thanks!
- Atila Neves (4/12) Mar 29 2017 Not only good to know, this... fixed it. So I was being stupid.
I'm trying to wrap a C++ library and have reduced my problem case to the code below. I get a linker error due to different name mangling (this is on Linux): main.d:(.text._Dmain+0x13): undefined reference to `_ZN3ns13ns212createStructERN3ns17OptionsE' The C++ object file has instead a symbol called _ZN3ns13ns212createStructERNS_7OptionsE. To make matters worse and me more confused, according to https://demangler.com, they both demangle to the same thing: `ns1::ns2::createStruct(ns1::Options&)`. If you're wondering why there's two D files it's because trying to do: extern(C++, ns1) {... } extern(C++, ns1.ns2) {...} doesn't compile since there would be two D versions of ns1, which is... mildly annoying. I even took `const` off of the parameter in case that was the problem but clearly not. Atila impl.cpp: namespace ns1 { struct Options { }; struct Struct { }; namespace ns2 { ns1::Struct* createStruct(Options&) { return nullptr; } } } header.d: extern(C++, ns1) { struct Options { } struct Struct { } } main.d: extern(C++, ns1.ns2) { import header; Struct* createStruct(ref Options); } void main() { import header; Options options; auto s = createStruct(options); }
Mar 28 2017
That's a mangling compression scheme (possibly tunable via gcc options), from https://github.com/gchatelet/gcc_cpp_mangling_documentation:To save space a compression scheme is used where symbols that appears multiple times are then substituted by an item from the sequence : S_, S0_, S1_, S2_, etc ...As to nested C++ namespaces - `extern(C++, ns1) { ... extern(C++, ns2) { ... } }` should work in a single D file.
Mar 28 2017
On Tuesday, 28 March 2017 at 16:30:19 UTC, kinke wrote:That's a mangling compression scheme (possibly tunable via gcc options), from https://github.com/gchatelet/gcc_cpp_mangling_documentation:Good to know, thanks! AtilaTo save space a compression scheme is used where symbols that appears multiple times are then substituted by an item from the sequence : S_, S0_, S1_, S2_, etc ...As to nested C++ namespaces - `extern(C++, ns1) { ... extern(C++, ns2) { ... } }` should work in a single D file.
Mar 28 2017
On Tuesday, 28 March 2017 at 16:30:19 UTC, kinke wrote:That's a mangling compression scheme (possibly tunable via gcc options), from https://github.com/gchatelet/gcc_cpp_mangling_documentation:Not only good to know, this... fixed it. So I was being stupid. Thanks! AtilaTo save space a compression scheme is used where symbols that appears multiple times are then substituted by an item from the sequence : S_, S0_, S1_, S2_, etc ...As to nested C++ namespaces - `extern(C++, ns1) { ... extern(C++, ns2) { ... } }` should work in a single D file.
Mar 29 2017