From 0bd4901a174786a61fadf484f3b8932169533cd4 Mon Sep 17 00:00:00 2001 From: emekoi Date: Sat, 30 Mar 2019 00:06:04 -0500 Subject: [PATCH] fixed linking of system libraries on mingw --- src/libc_installation.hpp | 2 -- src/link.cpp | 24 ++++++++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/libc_installation.hpp b/src/libc_installation.hpp index 765ae4ec56..171cc963bf 100644 --- a/src/libc_installation.hpp +++ b/src/libc_installation.hpp @@ -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 diff --git a/src/link.cpp b/src/link.cpp index d7532d96e3..00d70d5e63 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -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)); }