www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.ldc - Error message when trying to link single D file to produce exe

reply Cecil Ward <cecil cecilward.com> writes:
I’ve just downloaded ldc and I can successfully generate either 
an object file or asm output file from a single .d source. I’ve 
no idea where to find a suitable linker ( or make ) with which I 
can either link in object files from d- and non-d language 
sources or even just generate an  exe from a single hello world 
.d -> .exe first.

1. I got an error message below.
2. I’ve run ldc on linux before, but osx is new to me. Where do I 
find a suitable linker and what is it called ?

I’m running on osx ventura Aarch64 targeting self, not 
cross-compiling.

Here’s what happened

cecil Mac-mini ~ %  ./ldc mac_hex_5.d --link-internally
lld: error: must specify -arch
Error: linking with LLD failed
The file "./ldc" is just a tiny one-line bash script that adds 
flags "-O3 -release -mcpu=native" and provides the path to the 
compiler.
Jun 09 2023
next sibling parent reply ryuukk_ <ryuukk.dev gmail.com> writes:
Are you using ARM mac or Intel?

If ARM try to add this: ``-arch arm64``

If Intel try to add this: ``-arch x86_64``

It shouldn't be needed tho, if you are using ARM mac, make sure 
you downloaded the ARM version, and not the Intel one, otherwise 
it'll run with Rosetta, wich i suspect is what the issue is
Jun 09 2023
parent Cecil Ward <cecil cecilward.com> writes:
On Saturday, 10 June 2023 at 03:49:22 UTC, ryuukk_ wrote:
 Are you using ARM mac or Intel?

 If ARM try to add this: ``-arch arm64``

 If Intel try to add this: ``-arch x86_64``

 It shouldn't be needed tho, if you are using ARM mac, make sure 
 you downloaded the ARM version, and not the Intel one, 
 otherwise it'll run with Rosetta, wich i suspect is what the 
 issue is
I’m an ARM Mac. I tried your suggestion, different error: cecil Mac-mini ~ % ./ldc mac_5.d --link-internally -arch arm64ldc2: Unknown command line argument '-arch'. Try: '/Users/cecil/ldc2-1.32.2-osx-arm64/bin/ldc2 --help' ldc2: Did you mean '--march'? cecil Mac-mini ~ %
Jun 09 2023
prev sibling parent reply Cecil Ward <cecil cecilward.com> writes:
On Saturday, 10 June 2023 at 03:24:51 UTC, Cecil Ward wrote:
 I’ve just downloaded ldc and I can successfully generate either 
 an object file or asm output file from a single .d source. I’ve 
 no idea where to find a suitable linker ( or make ) with which 
 I can either link in object files from d- and non-d language 
 sources or even just generate an  exe from a single hello world 
 .d -> .exe first.

 1. I got an error message below.
 2. I’ve run ldc on linux before, but osx is new to me. Where do 
 I find a suitable linker and what is it called ?

 I’m running on osx ventura Aarch64 targeting self, not 
 cross-compiling.

 Here’s what happened

 cecil Mac-mini ~ %  ./ldc mac_hex_5.d --link-internally
 lld: error: must specify -arch
 Error: linking with LLD failed
 The file "./ldc" is just a tiny one-line bash script that adds 
 flags "-O3 -release -mcpu=native" and provides the path to the 
 compiler.
I’ve since fixed one of the problems, that of being able to compile a single .d file to an exe. That now works because I did a new download of ldc from a different source, and the new package is perhaps more complete. Before I downloaded the compiler from the LDC website in a .tar.xz file (or similar) and then just untar-ed them into a subdirectory below my home directory. After that I had the error message and didn’t know how to make a .exe from a single .d. Now I did a "brew install ldc2" (or similar) using the homebrew package manager for osx. I now get an exe (which has bugs in it, but that’s probably my fault, it used to work though.) I am still at a loss as to where to find a linker. What am I supposed to be looking for and do I have to download the llvm c compiler to get a linker included in that package?
Jun 10 2023
parent reply kinke <noone nowhere.com> writes:
On Saturday, 10 June 2023 at 12:55:10 UTC, Cecil Ward wrote:
 I am still at a loss as to where to find a linker. What am I 
 supposed to be looking for and do I have to download the llvm c 
 compiler to get a linker included in that package?
Don't use `-link-internally` for non-Windows targets unless you know exactly what you are doing. See https://github.com/ldc-developers/ldc/issues/2717 and https://github.com/ldc-developers/ldc/pull/2203#issuecomment-339167131 for reasons, further links and cmdline examples. E.g., the `-arch` for the internal linker (an ld64-compatible LLD) would need to be specified as `-L-arch -Larm64` in the LDC cmdline. Linking for Posix targets is normally done through the C compiler (`cc`), which adds lots of cmdline options for the underlying linker (Apple: `ld64`), so that it finds the required C libs etc. I don't use Apple, but I guess an Xcode installation is required to have a C compiler (Apple clang) and Apple's ld64 linker. Use `-v` in the LDC cmdline to print the 'linker' command executed by LDC. Additionally use `-Xcc=-v` (without `-link-internally`) to make the C compiler print the actual linker cmdline (which would approximately be the one you'd need when linking with `-link-internally`).
Jun 10 2023
parent Cecil Ward <cecil cecilward.com> writes:
On Saturday, 10 June 2023 at 14:06:46 UTC, kinke wrote:
 On Saturday, 10 June 2023 at 12:55:10 UTC, Cecil Ward wrote:
 [...]
Use `-v` in the LDC cmdline to print the 'linker' command executed by LDC. Additionally use `-Xcc=-v` (without `-link-internally`) to make the C compiler print the actual linker cmdline (which would approximately be the one you'd need when linking with `-link-internally`).
Fantastic, thank you for your help, you’ve given me some things to research. The download package said something about fetching ‘Xcode’ or components from it. I found that the tools that I will need are already there. ld clang, everything.
Jun 10 2023