Skip to content

Commit d092ad2

Browse files
committed
Pass -lfoo to linker rather than -l foo.
1 parent 524ad9b commit d092ad2

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/librustc_codegen_llvm/back/linker.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,15 @@ impl<'a> GccLinker<'a> {
159159
self
160160
}
161161

162+
fn add_lib<S>(&mut self, lib: S) -> &mut Self
163+
where S: AsRef<OsStr>
164+
{
165+
let mut os = OsString::from("-l");
166+
os.push(lib.as_ref());
167+
self.cmd.arg(os);
168+
self
169+
}
170+
162171
fn takes_hints(&self) -> bool {
163172
!self.sess.target.target.options.is_like_osx
164173
}
@@ -185,8 +194,8 @@ impl<'a> GccLinker<'a> {
185194
}
186195

187196
impl<'a> Linker for GccLinker<'a> {
188-
fn link_dylib(&mut self, lib: &str) { self.hint_dynamic(); self.cmd.arg("-l").arg(lib); }
189-
fn link_staticlib(&mut self, lib: &str) { self.hint_static(); self.cmd.arg("-l").arg(lib); }
197+
fn link_dylib(&mut self, lib: &str) { self.hint_dynamic(); self.add_lib(lib); }
198+
fn link_staticlib(&mut self, lib: &str) { self.hint_static(); self.add_lib(lib); }
190199
fn link_rlib(&mut self, lib: &Path) { self.hint_static(); self.cmd.arg(lib); }
191200
fn include_path(&mut self, path: &Path) { self.cmd.arg("-L").arg(path); }
192201
fn framework_path(&mut self, path: &Path) { self.cmd.arg("-F").arg(path); }
@@ -202,7 +211,7 @@ impl<'a> Linker for GccLinker<'a> {
202211

203212
fn link_rust_dylib(&mut self, lib: &str, _path: &Path) {
204213
self.hint_dynamic();
205-
self.cmd.arg("-l").arg(lib);
214+
self.add_lib(lib);
206215
}
207216

208217
fn link_framework(&mut self, framework: &str) {
@@ -238,7 +247,7 @@ impl<'a> Linker for GccLinker<'a> {
238247
v.push(lib);
239248
self.linker_arg(&v);
240249
} else {
241-
self.linker_arg("--whole-archive").cmd.arg(lib);
250+
self.linker_arg("--whole-archive").add_lib(lib);
242251
self.linker_arg("--no-whole-archive");
243252
}
244253
}

0 commit comments

Comments
 (0)