macOS Sonoma Linker Issue
ryuukk_
ryuukk.dev at gmail.com
Sat Jan 20 21:12:12 UTC 2024
On Saturday, 20 January 2024 at 20:35:16 UTC, Renato wrote:
> On Friday, 22 December 2023 at 17:50:47 UTC, Johan wrote:
>> Some general advice:
>>
>> 1 - use `dub` from LDC's package (this may solve some arm64 vs
>> x86 issues when on Apple Silicon CPU)
>> 2 - when you use a new or different compiler, you have to
>> rebuild _all_ packages. So clear your dub cache.
>>
>> I think point 2 is causing your issues.
>>
>> -Johan
>
> Hi again, I hate to repeat myself, but the linker issues on
> MacOS keep happening, even after using this in the dub recipe:
>
> ```
> lflags "-ld_classic"
> ```
>
> Even though this helps, every now and then I am faced with a
> horrible error like this (happened on multiple projects):
>
> ```
> ld: warning: pointer not aligned at address 0x10017FA3A ('anon'
> + 115 from
> ../../../.dub/cache/prettyprint/1.0.9/build/library-unittest-zRys5rzGP6krRGvFrhQ1nw/libprettyprint.a(primitives_64_42b.o))
> ld: warning: pointer not aligned at address 0x10017FACD ('anon'
> + 115 from
> ../../../.dub/cache/prettyprint/1.0.9/build/library-unittest-zRys5rzGP6krRGvFrhQ1nw/libprettyprint.a(primitives_65_55a.o))
>
> .... hundreds of lines just like this
>
>
> ld: warning: pointer not aligned at address 0x100199171 ('anon'
> + 117 from
> ../../../.dub/cache/tested/0.9.5/build/library-unittest-GNkuLeNnFlMZmRhvBdmNgA/libtested.a(lifetime_2ae_75b.o))
> ld: unaligned pointer(s) for architecture x86_64
> clang: error: linker command failed with exit code 1 (use -v to
> see invocation)
> Error: linker exited with status 1
> Error /Users/renato/dlang/dmd-2.106.1/osx/bin/dmd failed with
> exit code 1.
> ```
>
> It doesn't matter if I use LDC or DMD. Both cause the same
> error.
>
> I've tried cleaning the DUB cache like this:
>
> ```
> rm -rf ~/.dub/cache
> ```
>
> But it doesn't help.
>
> It's very frustrating because I'm close to finishing my
> project, but this kind of random error really delays me... it
> seems that as I keep changing code, the linker eventually
> starts working again! I must be hitting some "bad path" in the
> compiler.
>
> So, if anyone who understands about linking on MacOS could have
> a look, here's a commit on the project I'm currently working on
> which shows this problem:
>
> https://github.com/renatoathaydes/dzipper/commit/54d1f90f18a17d87d71195df68d02089ca4cf27c
>
> If you checkout this commit, just run `dub test` and you should
> see the problem on MacOS Sonoma.
>
> Notice that the current state of my code is "in progress" so
> some stuff may not even be working properly yet, the tests may
> not even be passing, that's fine (if I only I could run the
> tests)... but as the error is on the linker, I believe it's
> compiling properly and there should never be any linker errors
> like this.
dub might not be passing this flag down to dependencies..
Try this env variable:
``LDFLAGS="$LDFLAGS -Wl,-ld_classic" dub build``
If that doesn't work, try this one:
``MACOSX_DEPLOYMENT_TARGET=11 dub build``
More information about the Digitalmars-d-learn
mailing list