Why export external(C) generate mangled names?

Daniel Kozak kozzi11 at gmail.com
Fri Oct 25 10:57:43 UTC 2019


On Fri, Oct 25, 2019 at 12:56 PM Daniel Kozak <kozzi11 at gmail.com> wrote:
>
> On Fri, Oct 25, 2019 at 12:35 PM Suliman via Digitalmars-d
> <digitalmars-d at puremagic.com> wrote:
> >
> > I thought that export extern(C) is needed for C compatibility.
> > But When I am compiling follow code
> >
> > export extern(C)
> > {
> >      void foo()
> >      {
> >      }
> > }
> >
> > I am getting section that have mangled names:
> >
> > �   foo.d �   �7nO �   � CV �,
> >  FLAT _TEXT CODE _DATA DATA CONST _BSS BSS �     �        �      i
> >     �    i        �      i        �    �   _foo �
> >    �   �   _foo  �   FMB FM FME �        �        �      �       �       �
> >    �     __D3foo12__ModuleInfoZ      �
> >
> > � �               foo  �
> >             �  �     �
> >
> > Why is __D3foo12__ModuleInfoZ added to obj file?
>
> Try to compile with -betterC

You should get:

[kozak at missandei ~]$ dmd -c -ofobj.o obj.d
[kozak at missandei ~]$ nm obj.o
0000000000000000 t
                 U _d_dso_registry
0000000000000000 R _D3obj12__ModuleInfoZ
0000000000000000 W foo
                 U __start_minfo
                 U __stop_minfo

[kozak at missandei ~]$ dmd -betterC -c -ofobj.o obj.d
[kozak at missandei ~]$ nm obj.o
0000000000000000 t
0000000000000000 W foo



More information about the Digitalmars-d mailing list