fixed linking of system libraries on mingw

This commit is contained in:
emekoi 2019-03-30 00:06:04 -05:00
parent 6cc443ee45
commit 0bd4901a17
2 changed files with 16 additions and 10 deletions

View File

@ -29,8 +29,6 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file);
Error ATTRIBUTE_MUST_USE zig_libc_find_native(ZigLibCInstallation *self, bool verbose);
#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_WINDOWS)
Error zig_libc_cc_print_file_name(const char *o_file, Buf *out, bool want_dirname, bool verbose);
#endif
#endif

View File

@ -1359,17 +1359,25 @@ static void construct_linker_job_coff(LinkJob *lj) {
}
if (link_lib->provided_explicitly) {
if (target_abi_is_gnu(lj->codegen->zig_target->abi)) {
static const char *test_names[3] = { "lib%s.dll.a", "lib%s.a", nullptr };
static const char *test_names[3] = { "%s\\lib%s.dll.a", "%s\\lib%s.a", nullptr };
bool exists = false;
for (size_t i = 0; test_names[i] != nullptr; i++) {
Buf *test_path = buf_sprintf(test_names[i], buf_ptr(link_lib->name));
bool exists = false;
if (os_file_exists(test_path, &exists) != ErrorNone) {
zig_panic("link: unable to check if file exists: %s", buf_ptr(test_path));
} else if (exists) {
lj->args.append(buf_ptr(test_path));
for (size_t i = 0; test_names[i] != nullptr && !exists; i++) {
for (size_t j = 0; j < g->lib_dirs.length; j += 1) {
const char *lib_dir = g->lib_dirs.at(j);
Buf *test_path = buf_sprintf(test_names[i], lib_dir, buf_ptr(link_lib->name));
if (os_file_exists(test_path, &exists) != ErrorNone) {
zig_panic("link: unable to check if file exists: %s", buf_ptr(test_path));
} else if (exists) {
lj->args.append(buf_ptr(test_path));
break;
}
}
}
if (!exists) {
zig_panic("link: unable to find library: %s", buf_ptr(link_lib->name));
}
} else {
lj->args.append(buf_ptr(link_lib->name));
}