-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
zig cc
: --as-needed
is an unsupported linker flag
#10164
Comments
Thanks for the report! Looking into this. |
I solved this by changing the default to strip dependencies on dynamic libraries that are unused by default. So you won't even need the
Looks like that should unblock you for Linux. As for macOS, I extracted #10192. But let's chat about this use case- I happen to have a local branch of https://github.com/andrewrk/zig-sdl that works for x86_64-macos (tested on Catalina). There are a couple of issues with it that I am working with @kubkon to fix. But it sounds like maybe this is what you would want, yeah? The idea is that you would copy this code into your repository, and then you end up with a macOS binary that has a static dependency on SDL and therefore can't run into any problems with trying to dynamic link it. |
Thanks for looking into this! Ultimately, we ended up using another toolchain for Windows -> Mac, but we will definitely check back on Zig + Mac in the future. Just to elaborate on our usecase, for both Linux/Mac we:
Using a Zig CMake toolchain and X11/GL/etc borrowed from Steam Runtime sysroots, it seems like this works pretty well for Windows -> Linux compilation with For Windows -> Mac, we ran into some link errors with the Zig MachO linker and SDL2, and we also had to do some workarounds to get Objective-C compilation working, but we will see about creating tickets for these once we can find some time. |
Would you be able to provide a small repro of Win->Mac? I wrote zld (which is our in-house MachO linker) and with a repro I can come up with a solution fairly quickly. Also, did you use released zig version (0.8.1) or upstream/master? |
We used zig master built from source. I don't have the stack trace for the error any longer (sorry), but the error occurred here: Line 1214 in 4e5a88b
leading to an assert assert(!self.containsContext(key, ctx)); failing.
|
@matpow2 You'd be surprised but this is a huge hint. However, I'd still need a repro case - the error will be related to a bug in processing dylibs either directly from the linker invocation line (if you could paste it, even abridged, that would be of help) or in handling of the dylib dependents (recursive descent of the re-exported dylibs). |
I think this was approximately the link command:
Hope it helps! |
Zig Version
0.9.0-dev.1625+d3a099c14
Steps to Reproduce
This can be easily reproduced using a command like
If you use
objdump -p
on the resulting executable, you will also seeDT_NEEDED
entries for e.g.ibus-1.0
.Expected Behavior
zig cc
should accept--as-needed
as a linker flag such that unnecessaryDT_NEEDED
entries are removed.--as-needed
is supported by bothlld
and GNUld
, butzig cc
needs to be changed to allow for this particular flag.Actual Behavior
zig cc
gave a messagewarning: unsupported linker arg: --as-needed
.This is especially problematic when compiling libraries like SDL2 which rely on the
--as-needed
behavior to remove suchDT_NEEDED
entries.Otherwise, the executable will depend on dynamic libraries which might not exist on the host system.
It seems like #10050 is a different issue related to
-lgcc_s
/-lunwind
, so creating a new issue here.As a sidenote, we are currently evaluating using
zig cc
as a cross compiler from Windows -> Linux/Mac for our games (Baba Is You, Mighty Goose, etc).This has worked perfectly so far for Linux, except for this particular issue :)
The text was updated successfully, but these errors were encountered: