Bug 16677 – -L flag ignores quotes in the arguments passed to the linker
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2016-11-09T11:12:08Z
Last change time
2019-10-18T06:13:09Z
Keywords
pull
Assigned to
No Owner
Creator
Atila Neves
Comments
Comment #0 by atila.neves — 2016-11-09T11:12:08Z
On Windows 32-bit, linking with dmd and passing, say, `-L/LIBPATH:"C:/Program Files (x86)/foo/bar"`, dmd calls `link.exe` without the quotes which results in linker error trying to link `C:/Program.obj` because of the space. Since `C:/Program Files (x86)/` is where a lot of system libraries live, the user doesn't really have a choice but to call `link.exe` manually, which isn't easy to set up with dub.
Comment #1 by sprink.noreply — 2016-11-11T02:41:35Z
The problem might be Window's shell consuming the quotes, not that DMD ignores them. A potential workaround would be to escape the quotes you want passed to the linker. You'd have to look it up, I think it is different for cmd and powershell.
https://github.com/dlang/dmd/blob/v2.072.0/src/link.d#L267
Adding quotes around passed in linker flags would make it simpler, not having to deal with escaping the quotes in the command.
Comment #2 by atila.neves — 2016-12-23T17:46:59Z
If the problem was cmd.exe then cl.exe would also suffer from this, which doesn't happen.
Comment #3 by sprink.noreply — 2017-01-03T03:21:26Z
(In reply to Atila Neves from comment #2)
> If the problem was cmd.exe then cl.exe would also suffer from this, which
> doesn't happen.
No it wouldn't, cl.exe doesn't get the quotes either. So there no quotes to ignore or to process. It's a matter of how DMD sends arguments to the process, it does so by building an entire string. So it just concatenates the passed argument into the list, but it's devoid of it's quotes because of cmd.exe. Escaping the quotes so cmd.exe includes the quotes solves the problem.
Comment #4 by goalitium — 2019-04-24T16:30:57Z
We just hit this bug too with DMD, but passing the same quoted path to LDC does get handled correctly:
> ldc2 -m64 "-L/LIBPATH:C:/Program Files (x86)/foo/bar" hello.d
> dmd -m64 "-L/LIBPATH:C:/Program Files (x86)/foo/bar" hello.d
LINK : fatal error LNK1181: cannot open input file 'Files.obj'
Error: linker exited with status 1181
Comment #5 by doob — 2019-04-25T09:26:36Z
*** Issue 19821 has been marked as a duplicate of this issue. ***
Comment #6 by kinke — 2019-10-07T20:16:42Z
This seems to be a DMD bug when building the linker cmdline on Windows, at least for link.exe - it simply doesn't do any quoting and writes the linker flag directly into the cmdline string. On POSIX, an arguments array is used.
POSIX:
$ dmd '-Labc def' foo.d
/usr/bin/ld: error: cannot open abc def: No such file or directory
Windows:
dmd "-Labc def" -m64 foo.d
LINK : fatal error LNK1181: cannot open input file 'abc.obj'
[The current way to make it work is an extremely ugly `dmd "-L\"abc def\"" -m64 foo.d`.]
Comment #7 by dlang-bot — 2019-10-07T20:54:15Z
@kinke created dlang/dmd pull request #10459 "Fix linker flags with blanks on Windows" fixing this issue:
- Fix linker flags with blanks on Windows
Fixes issue 19821 and 16677, for link.exe only though.
https://github.com/dlang/dmd/pull/10459
Comment #8 by dlang-bot — 2019-10-18T06:13:09Z
dlang/dmd pull request #10459 "[stable] Fix linker flags with blanks on Windows" was merged into stable:
- ec6de46e76efd34d3f8a5d97f89cd1f42beb1cdd by Martin Kinkelin:
Fix linker flags with spaces on Windows
Fixes issue 19821 and 16677 for MS link.exe only (I haven't checked
Optlink).
https://github.com/dlang/dmd/pull/10459