www.digitalmars.com         C & C++   DMDScript  

D.gnu - Undefined _D10TypeInfo_l6__initZ and _D15TypeInfo_Struct6__vtblZ added

reply "Liran Zvibel" <liran weka.io> writes:
Hi,

I would like to use some D code in a C binary
.
Part of the D functionality used is by instantiating templated 
structs.

Even if I just try to compile the following simple code:

extern (C) {
     alias mytpye = BLA!(int);
     struct BLA(T) {
         T x;
     }
}

With the following gcd flags:
-fno-invariants -fno-in -fno-out -fno-bounds-check -O3 
-fno-assert -c -nophoboslib  -nostdlib

I still have 3 undefined symbols:
_D10TypeInfo_i6__initZ _D15TypeInfo_Struct6__vtblZ _Dmodule_ref

I can alway just define them in the C glue code and get it over 
with, but I would like to understand what I SHOULD do to get it 
to easily link into a normal C executable.

Thanks!
Liran
Jan 26 2015
next sibling parent "Laeeth Isharc" <laeethnospam nospamlaeeth.com> writes:
On Monday, 26 January 2015 at 17:50:59 UTC, Liran Zvibel wrote:
 Hi,

 I would like to use some D code in a C binary
 .
 Part of the D functionality used is by instantiating templated 
 structs.

 Even if I just try to compile the following simple code:

 extern (C) {
     alias mytpye = BLA!(int);
     struct BLA(T) {
         T x;
     }
 }

 With the following gcd flags:
 -fno-invariants -fno-in -fno-out -fno-bounds-check -O3 
 -fno-assert -c -nophoboslib  -nostdlib

 I still have 3 undefined symbols:
 _D10TypeInfo_i6__initZ _D15TypeInfo_Struct6__vtblZ _Dmodule_ref

 I can alway just define them in the C glue code and get it over 
 with, but I would like to understand what I SHOULD do to get it 
 to easily link into a normal C executable.

 Thanks!
 Liran
Is the BLA struct instantiated somewhere?
Jan 26 2015
prev sibling next sibling parent reply "Mike" <none none.com> writes:
On Monday, 26 January 2015 at 17:50:59 UTC, Liran Zvibel wrote:

 With the following gcd flags:
 -fno-invariants -fno-in -fno-out -fno-bounds-check -O3 
 -fno-assert -c -nophoboslib  -nostdlib

 I still have 3 undefined symbols:
 _D10TypeInfo_i6__initZ _D15TypeInfo_Struct6__vtblZ _Dmodule_ref
If you're compliling with -nophoboslib, you are also compiling without the runtime, not just phobos. GDC compiles them in one library, IIRC. Therefore, you have to implement those parts of the runtime the compiler inserts implicitly. This includes TypeInfo and ModuleInfo. You can compile with -fno-emit-moduleinfo to get rid of the _Dmodule_ref symbol, but there's no equivalent yet for TypeInfo. Depending on what features of D you are employing, you may be able to stub out the TypeInfo in your object.d file. I have an example here: https://github.com/JinShil/D_Runtime_ARM_Cortex-M_study/wiki/1.3-Structs. For 64-bit it may need to be different. See: https://github.com/JinShil/druntime_level_0/blob/master/source/object.d I figured out the size of each `ignore` array by trial and error. Mike
Jan 26 2015
parent "Liran Zvibel" <liran weka.io> writes:
On Monday, 26 January 2015 at 23:21:23 UTC, Mike wrote:
 If you're compliling with -nophoboslib, you are also compiling 
 without the runtime, not just phobos.  GDC compiles them in one 
 library, IIRC.

 Therefore, you have to implement those parts of the runtime the 
 compiler inserts implicitly.  This includes TypeInfo and 
 ModuleInfo.  You can compile with -fno-emit-moduleinfo to get 
 rid of the _Dmodule_ref symbol, but there's no equivalent yet 
 for TypeInfo.

 Depending on what features of D you are employing, you may be 
 able to stub out the TypeInfo in your object.d file.  I have an 
 example here:
 https://github.com/JinShil/D_Runtime_ARM_Cortex-M_study/wiki/1.3-Structs.
  For 64-bit it may need to be different.  See: 
 https://github.com/JinShil/druntime_level_0/blob/master/source/object.d

 I figured out the size of each `ignore` array by trial and 
 error.

 Mike
I'm using https://github.com/JinShil/druntime_level_0/ and it works very well for me. Thank you very much! Liran
Feb 18 2015
prev sibling parent "Iain Buclaw via D.gnu" <d.gnu puremagic.com> writes:
On 26 January 2015 at 17:50, Liran Zvibel via D.gnu <d.gnu puremagic.com> wrote:
 Hi,

 I would like to use some D code in a C binary
 .
 Part of the D functionality used is by instantiating templated structs.

 Even if I just try to compile the following simple code:

 extern (C) {
     alias mytpye = BLA!(int);
     struct BLA(T) {
         T x;
     }
 }

 With the following gcd flags:
 -fno-invariants -fno-in -fno-out -fno-bounds-check -O3 -fno-assert -c
 -nophoboslib  -nostdlib
-frelease -O3 -c does the same as -fno-invariants -fno-in ...
 I still have 3 undefined symbols:
 _D10TypeInfo_i6__initZ _D15TypeInfo_Struct6__vtblZ _Dmodule_ref

 I can alway just define them in the C glue code and get it over with, but I
 would like to understand what I SHOULD do to get it to easily link into a
 normal C executable.
There is work underway to talk about what will need to be done to implement notypeinfo or a similarly named attribute. Until then you need to link against libdruntime - or a library that provides a minimal implementation/stubs (ie: minlibd) As I'm typing this, I can see Mike has replied, probably with this same answer. :) Iain.
Jan 26 2015