diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-06-07 18:21:35 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-06-08 01:31:10 -0400 |
| commit | 38e233845ef7fa5c8ccb2cd3ce053d1827f9ee42 (patch) | |
| tree | a89d88e64422523b2ef58acc0bb3137624e74188 /src | |
| parent | c313e3f509fb43b3e795cc7ae2f7bb70f59fbb3e (diff) | |
| download | zig-38e233845ef7fa5c8ccb2cd3ce053d1827f9ee42.tar.gz zig-38e233845ef7fa5c8ccb2cd3ce053d1827f9ee42.zip | |
link: windows: look for more DLL import lib path names
When linking with -lfoo syntax, this indicates to Zig that the
dependency should either be provided by Zig, or it should be dynamically
provided by the system.
For windows-gnu targets, the search path was "foo.lib". Now it
additionally looks for "libfoo.dll.a".
Closes #7799
Diffstat (limited to 'src')
| -rw-r--r-- | src/link/Coff.zig | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/link/Coff.zig b/src/link/Coff.zig index 983e78e9e9..9ab1c6d78a 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -1221,13 +1221,26 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void { try argv.append(comp.compiler_rt_static_lib.?.full_object_path); } + try argv.ensureUnusedCapacity(self.base.options.system_libs.count()); for (self.base.options.system_libs.keys()) |key| { const lib_basename = try allocPrint(arena, "{s}.lib", .{key}); if (comp.crt_files.get(lib_basename)) |crt_file| { - try argv.append(crt_file.full_object_path); - } else { - try argv.append(lib_basename); + argv.appendAssumeCapacity(crt_file.full_object_path); + continue; + } + if (try self.findLib(arena, lib_basename)) |full_path| { + argv.appendAssumeCapacity(full_path); + continue; + } + if (target.abi.isGnu()) { + const fallback_name = try allocPrint(arena, "lib{s}.dll.a", .{key}); + if (try self.findLib(arena, fallback_name)) |full_path| { + argv.appendAssumeCapacity(full_path); + continue; + } } + log.err("DLL import library for -l{s} not found", .{key}); + return error.DllImportLibraryNotFound; } if (self.base.options.verbose_link) { @@ -1309,6 +1322,18 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void { } } +fn findLib(self: *Coff, arena: *Allocator, name: []const u8) !?[]const u8 { + for (self.base.options.lib_dirs) |lib_dir| { + const full_path = try fs.path.join(arena, &.{ lib_dir, name }); + fs.cwd().access(full_path, .{}) catch |err| switch (err) { + error.FileNotFound => continue, + else => |e| return e, + }; + return full_path; + } + return null; +} + pub fn getDeclVAddr(self: *Coff, decl: *const Module.Decl) u64 { assert(self.llvm_object == null); return self.text_section_virtual_address + decl.link.coff.text_offset; |
