digitalmars.D.learn - std.int128 not working with -betterC enabled
- Renato (29/29) Dec 20 2023 I wanted to write a small program using betterC that needs to use
- Renato (21/36) Dec 20 2023 This problem does not seem to be specific to int128 or even to
- Renato (5/20) Dec 20 2023 Ouch! I just forgot `-main` :D but yeah, the error does look
- Richard (Rikki) Andrew Cattermole (2/2) Dec 20 2023 Yes that is to be expected.
- Renato (3/5) Dec 20 2023 How do I compile that into my program?
- Richard (Rikki) Andrew Cattermole (3/10) Dec 20 2023 You copy the file from druntime into your project, and add it to your
- Matheus Catarino (5/34) Dec 22 2023 Would there be any reason not to use `core.int128`?
- Richard (Rikki) Andrew Cattermole (5/10) Dec 22 2023 Yes there is.
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
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
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
Yes that is to be expected. It is not templated, and hasn't been compiled into your program.
Dec 20 2023
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
On 21/12/2023 10:51 AM, Renato wrote:On Wednesday, 20 December 2023 at 19:11:15 UTC, Richard (Rikki) Andrew Cattermole wrote:You copy the file from druntime into your project, and add it to your programs compile command.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
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
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