-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Pass -lfoo to linker rather than -l foo. #51197
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Whoops, I got two similar lines of code mixed up and changed the wrong one. Fixed. |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Ping from triage, @michaelwoerister ! |
Looks good but seems to have compilation errors still. |
@comex, This PR failed travis, do you think you'll be able to look into that? |
Thank you for this PR @comex! Unfortunately we haven't heard from you on this in a while, so I'm closing the PR to keep things tidy. Don't worry though, if you'll have time again in the future please reopen this PR, we'll be happy to review it again! |
When invoking the linker and trying to link against a specific library, rustc currently passes
-l foo
as two separate arguments, rather than the more common syntax-lfoo
. GCC, Clang, and GNU ld all support-l foo
, but Darwin ld64 does not. By default, rustc currently uses the C compiler as its linker on all platforms (other than wasm), so it passes-l foo
toclang
, which then transforms it to-lfoo
when invokingld
. However, if you try to pass-C linker=ld
– or, more usefully,-C linker=ld64.lld
– it gets confused. Since-lfoo
is the preferred form on all Unix platforms, use it everywhere.As a side benefit, this makes printed linker command lines significantly more succinct, given that rustc wraps every argument in quotes, so you currently get things like
"-l" "System" "-l" "resolv" "-l" "pthread" "-l" "c" "-l" "m"
. (Of course, this could be improved further by omitting the quotes entirely for arguments that don't contain spaces.)This PR is simply a plagiarized subset of PR #46255, written by tamird, which @alexcrichton requested to be deferred until #48125 landed – something that's since happened. Actually, everything in that PR seems necessary for linking using
ld64
directly to work properly, but since I'm not the original author, I'm too lazy to convince myself that it's all correct. Landing this by itself will at least make some basic cases work.