www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - interfacing Cpp - GCC Dual ABI abi_tag in name mangling

reply =?UTF-8?B?2LPZhNmK2YXYp9mGINin2YTYs9mH?= writes:
GCC has this attribute called abi_tag that they put on any 
function that returns std::string or std::list, for the rational 
behind that read 
here:https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html .
the special thing with this attribute is that it adds something 
to the name mangling of your function, and I don't know how to 
represent that in D.
for example the cpp function "std::string func()" will be mangled 
as "func[abi:cxx11]()".
any ideas?
Apr 29
next sibling parent reply kinke <noone nowhere.com> writes:
On Saturday, 29 April 2017 at 18:08:16 UTC, سليمان السهمي 
(Soulaïman Sahmi) wrote:
 GCC has this attribute called abi_tag that they put on any 
 function that returns std::string or std::list
The usual workaround is compiling the C++ source with _GLIBCXX_USE_CXX11_ABI=0 for gcc >= 5.
Apr 29
parent =?UTF-8?B?2LPZhNmK2YXYp9mGINin2YTYs9mH?= writes:
On Saturday, 29 April 2017 at 19:16:14 UTC, kinke wrote:
 On Saturday, 29 April 2017 at 18:08:16 UTC, سليمان السهمي 
 (Soulaïman Sahmi) wrote:
 GCC has this attribute called abi_tag that they put on any 
 function that returns std::string or std::list
The usual workaround is compiling the C++ source with _GLIBCXX_USE_CXX11_ABI=0 for gcc >= 5.
Thats what they said, the GNU guys have a very elegant way of deceiving people, especially when it comes to backwards compatibility. they made the flag on by default, and they said you could just opt out if you want. The problem is, if you opt out, you can't link to any code out there. because the flag is on by default and people just don't bother turning it off. In my case the function is in a cpp library that i don't own, and wouldn't bother recompiling every library i need to interface to. If I compile! my code with the flag off, I cannot call any function that takes std::string or std::list as an argument on those libraries that were compiled with the flag on. because they also add a namespace called __cxx11 to std::string and std::list arguments in the name mangling. and if I compile with the flag off the namespace disappears.
Apr 29
prev sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2017-04-29 20:08, سليمان السهمي (Soulaïman Sahmi) wrote:
 GCC has this attribute called abi_tag that they put on any function that
 returns std::string or std::list, for the rational behind that read
 here:https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html .
 the special thing with this attribute is that it adds something to the
 name mangling of your function, and I don't know how to represent that
 in D.
 for example the cpp function "std::string func()" will be mangled as
 "func[abi:cxx11]()".
 any ideas?
You can use pragma(mangle, "some mangling"); to set the mangled name of a symbol. -- /Jacob Carlborg
Apr 30
parent =?UTF-8?B?2LPZhNmK2YXYp9mGINin2YTYs9mH?= writes:
On Sunday, 30 April 2017 at 11:35:54 UTC, Jacob Carlborg wrote:
 You can use pragma(mangle, "some mangling"); to set the mangled 
 name of a symbol.
that's a quick hack, but sooner or later dmd needs to add some rules for this in the internal cpp mangler, since gcc is the main compiler in gnu/linux. at least provide an abi_tag attribute or something the user can put inside a version condition.
Apr 30