Commit 5aa2812507

Andrew Kelley <andrew@ziglang.org>
2020-03-29 19:17:21
linking is now aware -lm is provided by mingw-w64
1 parent c70471f
Changed files (2)
src/link.cpp
@@ -1903,7 +1903,7 @@ static void construct_linker_job_elf(LinkJob *lj) {
             // libc is linked specially
             continue;
         }
-        if (buf_eql_str(link_lib->name, "c++") || buf_eql_str(link_lib->name, "c++abi")) {
+        if (target_is_libcpp_lib_name(g->zig_target, buf_ptr(link_lib->name))) {
             // libc++ is linked specially
             continue;
         }
@@ -2470,7 +2470,12 @@ static void construct_linker_job_coff(LinkJob *lj) {
         if (buf_eql_str(link_lib->name, "c")) {
             continue;
         }
-        if (buf_eql_str(link_lib->name, "c++") || buf_eql_str(link_lib->name, "c++abi")) {
+        if (target_is_libcpp_lib_name(g->zig_target, buf_ptr(link_lib->name))) {
+            // libc++ is linked specially
+            continue;
+        }
+        if (g->libc == nullptr && target_is_libc_lib_name(g->zig_target, buf_ptr(link_lib->name))) {
+            // these libraries are always linked below when targeting glibc
             continue;
         }
         bool is_sys_lib = is_mingw_link_lib(link_lib->name);
src/target.cpp
@@ -1207,6 +1207,15 @@ bool target_is_libc_lib_name(const ZigTarget *target, const char *name) {
     if (strcmp(name, "c") == 0)
         return true;
 
+    if (target_abi_is_gnu(target->abi) && target->os == OsWindows) {
+        // mingw-w64
+
+        if (strcmp(name, "m") == 0)
+            return true;
+
+        return false;
+    }
+
     if (target_abi_is_gnu(target->abi) || target_abi_is_musl(target->abi) || target_os_is_darwin(target->os)) {
         if (strcmp(name, "m") == 0)
             return true;