[Issue 12238] Using pthread_mutex_t.init results in an undefined reference linker error.

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Aug 13 22:10:13 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=12238

--- Comment #1 from Joakim <joakim at airpost.net> ---
Created attachment 1385
  --> https://issues.dlang.org/attachment.cgi?id=1385&action=edit
nested union declaration causes incorrect compile if imported from another file

I just ran into this bug when trying to port some Android system headers from
C, except with nested unions in my case and with dmd-git-24e8347f1fa4 from a
week ago.  I can confirm that Kapps's testcase also doesn't work on linux/x86,
when tried with the latest stock dmd 2.065.

I've attached a couple source files to demonstrate the problem.  The structs
defined are exactly the ones I'm trying to port from Android, ASensorVector and
ASensorEvent shown here:

https://android.googlesource.com/platform/frameworks/native/+/jb-release/include/android/sensor.h

I build and run as so on linux/86 using stock dmd 2.065:

> clang -c foo.c
> dmd food.d foo.o
>./food

That works, since it's getting the struct declarations from the main source
file.  This doesn't:

> dmd -version=do_import food.d foo.o

food.o:food.d:function _Dmain: error: undefined reference to
'_D4fooi5foogo6__initZ'

Looking at the symbols generated, it appears that dmd is generating the right
symbols only if the union or nested union is declared in the local source file.
 Here's the symbols without do_import:

> dmd -c food.d
> nm -s food.o | grep foogo
00000000 V _D21TypeInfo_S4food5foogo6__initZ
00000000 T _D4food5foogo11__xopEqualsUKxS4food5foogoKxS4food5foogoZb
00000030 R _D4food5foogo6__initZ

With the do_import:
> dmd -version=do_import -c food.d
> nm -s food.o | grep foogo
         U _D4fooi5foogo6__initZ

It's that undefined symbol that causes the linker to fail.  Putting the
ASensorVector/ASensorEvent declarations in the same file also gets it to work
on Android/x86.

--


More information about the Digitalmars-d-bugs mailing list