www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - std.int128 not working with -betterC enabled

reply Renato <renato athaydes.com> writes:
I wanted to write a small program using betterC that needs to use 
int128.

This simple program works without -betterC:

```d
module dasc;

import std.int128;
import core.stdc.stdio;

extern (C):

int main() {
   auto n = Int128(128, 128);
   printf("n=%lu%lu", n.data.hi, n.data.lo);
   return 42;
}
```

But with -betterC:

```
dmd -L-ld_classic -betterC -run dasc.d
Undefined symbols for architecture x86_64:
   "__D3std6int1286Int1286__ctorMFNaNbNcNiNfllZSQBpQBoQBk", 
referenced from:
       _main in dasc.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to 
see invocation)
Error: linker exited with status 1

Compilation exited abnormally with code 1 at Wed Dec 20 19:11:56
```

I don't see anywhere whether int128 is supposed to work on 
-betterC. Is it not supported?
Dec 20 2023
next sibling parent reply Renato <renato athaydes.com> writes:
On Wednesday, 20 December 2023 at 18:16:00 UTC, Renato wrote:
 But with -betterC:

 ```
 dmd -L-ld_classic -betterC -run dasc.d
 Undefined symbols for architecture x86_64:
   "__D3std6int1286Int1286__ctorMFNaNbNcNiNfllZSQBpQBoQBk", 
 referenced from:
       _main in dasc.o
 ld: symbol(s) not found for architecture x86_64
 clang: error: linker command failed with exit code 1 (use -v to 
 see invocation)
 Error: linker exited with status 1

 Compilation exited abnormally with code 1 at Wed Dec 20 19:11:56
 ```

 I don't see anywhere whether int128 is supposed to work on 
 -betterC. Is it not supported?
This problem does not seem to be specific to int128 or even to -betterC. Just now, in another thread someone told me about the `-checkaction=context` compiler option... and when I use that, I get the same kind of error: ``` dmd -L-ld_classic -unittest -checkaction=context -run main.d Undefined symbols for architecture x86_64: "_main", referenced from: implicit entry/start for main executable (maybe you meant: __D4core6thread10threadbase10ThreadBase7sm_mainCQBtQBrQBnQBe, __D4core6thread8osthread16_mainThreadStoreG312v ) ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) Error: linker exited with status 1 ``` I am looking forward for the new DMD compiler version to be released which fixes the MacOS linker issues!
Dec 20 2023
parent Renato <renato athaydes.com> writes:
On Wednesday, 20 December 2023 at 18:46:41 UTC, Renato wrote:

 ```
 dmd -L-ld_classic -unittest -checkaction=context -run main.d
 Undefined symbols for architecture x86_64:
   "_main", referenced from:
      implicit entry/start for main executable
      (maybe you meant: 
 __D4core6thread10threadbase10ThreadBase7sm_mainCQBtQBrQBnQBe, 
 __D4core6thread8osthread16_mainThreadStoreG312v )
 ld: symbol(s) not found for architecture x86_64
 clang: error: linker command failed with exit code 1 (use -v to 
 see invocation)
 Error: linker exited with status 1
 ```
Ouch! I just forgot `-main` :D but yeah, the error does look similar! I can't delete my previous message, it seems, unfortunately...
 I am looking forward for the new DMD compiler version to be 
 released which fixes the MacOS linker issues!
Well, that part is still true.
Dec 20 2023
prev sibling next sibling parent reply "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
Yes that is to be expected.

It is not templated, and hasn't been compiled into your program.
Dec 20 2023
parent reply Renato <renato athaydes.com> writes:
On Wednesday, 20 December 2023 at 19:11:15 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
 Yes that is to be expected.

 It is not templated, and hasn't been compiled into your program.
How do I compile that into my program?
Dec 20 2023
parent "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 21/12/2023 10:51 AM, Renato wrote:
 On Wednesday, 20 December 2023 at 19:11:15 UTC, Richard (Rikki) Andrew 
 Cattermole wrote:
 Yes that is to be expected.

 It is not templated, and hasn't been compiled into your program.
How do I compile that into my program?
You copy the file from druntime into your project, and add it to your programs compile command.
Dec 20 2023
prev sibling parent reply Matheus Catarino <matheus-catarino hotmail.com> writes:
On Wednesday, 20 December 2023 at 18:16:00 UTC, Renato wrote:
 I wanted to write a small program using betterC that needs to 
 use int128.

 This simple program works without -betterC:

 ```d
 module dasc;

 import std.int128;
 import core.stdc.stdio;

 extern (C):

 int main() {
   auto n = Int128(128, 128);
   printf("n=%lu%lu", n.data.hi, n.data.lo);
   return 42;
 }
 ```

 But with -betterC:

 ```
 dmd -L-ld_classic -betterC -run dasc.d
 Undefined symbols for architecture x86_64:
   "__D3std6int1286Int1286__ctorMFNaNbNcNiNfllZSQBpQBoQBk", 
 referenced from:
       _main in dasc.o
 ld: symbol(s) not found for architecture x86_64
 clang: error: linker command failed with exit code 1 (use -v to 
 see invocation)
 Error: linker exited with status 1

 Compilation exited abnormally with code 1 at Wed Dec 20 19:11:56
 ```

 I don't see anywhere whether int128 is supposed to work on 
 -betterC. Is it not supported?
Would there be any reason not to use `core.int128`? Currently, I used it to make a TigerbeetleDB client (Zig database) in D (betterC). https://github.com/batiati/tigerbeetle-clients-benchmarks/blob/f86216834bd04e1e06bede2a2e31b64df0dc98f1/d/modules/tb_client.d#L12
Dec 22 2023
parent "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
On 23/12/2023 11:41 AM, Matheus Catarino wrote:
 Would there be any reason not to use |core.int128|?
 
 Currently, I used it to make a TigerbeetleDB client (Zig database) in D 
 (betterC). 
 https://github.com/batiati/tigerbeetle-clients-benchmarks/blob/f86216834bd04e1e06bede2a2e31b64df0dc98f1/d/mod
les/tb_client.d#L12 <https://github.com/batiati/tigerbeetle-clients-benchmarks/blob/f86216834bd04e1e06bede2a2e31b64df0dc98f1/d/modules/tb_client.d#L12>
Yes there is. With -betterC, it is not linked in. Therefore it will fail to link. Note: ldc/gdc may recognize it and switch it to backend specific things instead of using those functions, which will work.
Dec 22 2023