www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Error with -betterC

reply Maximilian Naderer <maximilian.wallinger outlook.com> writes:
I have the following struct with i compile with -betterC into a 
static library.

```d
struct SubmitDesc {

     union {
         uint[4] viewport;
         struct {
             uint vpx;
             uint vpy;
             uint vpw;
             uint vph;
         }
     }

     union {
         float[4] clearColors;
         struct {
             float[4] clearColor0;
             // float[4] clearColor1;
             // float[4] clearColor2;
             // float[4] clearColor3;
         }
     }

     bool clearColorBuffer;
     bool clearDepthBuffer;
}
```

I compile another binary which dub does all automatically which 
is not -betterC where I try to use my static library and the 
strcut but I get a linker error all the time (Below.
Can somebody point me what I'm missing ?

Of course when I compile everything without -betterC it works 
just fine. Is the -betterC config not creating the equals, hash 
functions which are generated by D ?

```d
struct DrawPass {
     CommandList* commands;
     SubmitDesc submitDesc;
}

DrawPass mPassOpaque;

```


error: /usr/bin/ld: 
build/.objs/examples/linux/x86_64/debug/source/examples/example.d.o:(.data._D46TypeInfo_S3leo11graphicsapi6common10Submi
Desc6__initZ+0x30): undefined reference to
`leo.graphicsapi.common.SubmitDesc.__xtoHash(ref
const(leo.graphicsapi.common.SubmitDesc))'
/usr/bin/ld: 
build/.objs/examples/linux/x86_64/debug/source/examples/example.d.o:(.data._D46TypeInfo_S3leo11graphicsapi6common10Submi
Desc6__initZ+0x38): undefined reference to
`leo.graphicsapi.common.SubmitDesc.__xopEquals(ref
const(leo.graphicsapi.common.SubmitDesc)) const'
collect2: error: ld returned 1 exit status
Error: undefined reference to 
`leo.graphicsapi.common.SubmitDesc.__xtoHash(ref 
const(leo.graphicsapi.common.SubmitDesc))`
Error: undefined reference to 
`leo.graphicsapi.common.SubmitDesc.__xopEquals(ref 
const(leo.graphicsapi.common.SubmitDesc)) const`
        perhaps a library needs to be added with the `-L` flag or 
`pragma(lib, ...)`
Error: linker exited with status 1
        cc 
build/.objs/examples/linux/x86_64/debug/source/examples/example.d.o
build/.objs/examples/linux/x86_64/debug/source/examples/graphicsapi/ex0_
lear_background.d.o build/.objs/examples/linux/x86_64/debug/sour
e/examples/main.d.o build/.objs/examples/linux/x86_64/debug/deps/bindbc-glfw/source/bindbc
glfw/bindstatic.d.o build/.objs/examples/linux/x86_64/debug/deps/bindbc-glfw/source/bindbc/
lfw/binddynamic.d.o build/.objs/examples/linux/x86_64/debug/deps/bindbc-glfw/source/bin
bc/glfw/package.d.o build/.objs/examples/linux/x86_64/debug/deps/bindbc-glfw/source/b
ndbc/glfw/types.d.o build/.objs/examples/linux/x86_64/debug/deps/bindbc-loader/source/bindb
/loader/package.d.o build/.objs/examples/linux/x86_64/debug/deps/bindbc-loader/source/bindbc/
oader/sharedlib.d.o build/.objs/examples/linux/x86_64/debug/deps/bindbc-loader/source/bind
c/loader/system.d.o build/.objs/examples/linux/x86_64/debug/deps/bindbc-loader/source/bindb
/loader/codegen.d.o -o build/linux/x86_64/debug/examples -m64 -Xlinker
--export-dynamic -Lbuild/linux/x86_64/debug -lleo -L/usr/lib -Xlinker -Bstatic
-lphobos2 -Xlinker -Bdynamic -lpthread -lm -lrt -ldl
Nov 08
parent reply "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 09/11/2024 12:10 AM, Maximilian Naderer wrote:
 Is the -betterC config not creating the equals, hash functions which are 
 generated by D ?
I just checked, no.
Nov 08
parent reply Maximilian Naderer <maximilian.wallinger outlook.com> writes:
On Friday, 8 November 2024 at 11:21:33 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
 On 09/11/2024 12:10 AM, Maximilian Naderer wrote:
 Is the -betterC config not creating the equals, hash functions 
 which are generated by D ?
I just checked, no.
Hello Rikki, Thanks for checking. Just to confirm so this means these functions are not generated therefore this is why I get the linker errors ? Kind regards, Max
Nov 08
parent "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 09/11/2024 4:03 AM, Maximilian Naderer wrote:
 On Friday, 8 November 2024 at 11:21:33 UTC, Richard (Rikki) Andrew 
 Cattermole wrote:
 On 09/11/2024 12:10 AM, Maximilian Naderer wrote:
 Is the -betterC config not creating the equals, hash functions which 
 are generated by D ?
I just checked, no.
Hello Rikki, Thanks for checking. Just to confirm so this means these functions are not generated therefore this is why I get the linker errors ? Kind regards, Max
Yes.
Nov 08