[PATCH] D60094: [MSVC] If unable to find link.exe from a MSVC installation, look for link.exe next to cl.exe

Martin Storsjö via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 12 11:48:19 PDT 2019


mstorsjo updated this revision to Diff 194926.
mstorsjo retitled this revision from "[MSVC] If unable to find link.exe relative to MSVC, look for link.exe in the path" to "[MSVC] If unable to find link.exe from a MSVC installation, look for link.exe next to cl.exe".
mstorsjo edited the summary of this revision.
mstorsjo added a comment.

Updated to not look blindly for link(.exe) in the PATH, but look for cl.exe and look for link.exe next to it.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60094/new/

https://reviews.llvm.org/D60094

Files:
  lib/Driver/ToolChains/MSVC.cpp


Index: lib/Driver/ToolChains/MSVC.cpp
===================================================================
--- lib/Driver/ToolChains/MSVC.cpp
+++ lib/Driver/ToolChains/MSVC.cpp
@@ -488,8 +488,18 @@
     // their own link.exe which may come first.
     linkPath = FindVisualStudioExecutable(TC, "link.exe");
 
-    if (!TC.FoundMSVCInstall() && !llvm::sys::fs::can_execute(linkPath))
-      C.getDriver().Diag(clang::diag::warn_drv_msvc_not_found);
+    if (!TC.FoundMSVCInstall() && !llvm::sys::fs::can_execute(linkPath)) {
+      llvm::SmallString<128> ClPath;
+      ClPath = TC.GetProgramPath("cl.exe");
+      if (llvm::sys::fs::can_execute(ClPath)) {
+        linkPath = llvm::sys::path::parent_path(ClPath);
+        llvm::sys::path::append(linkPath, "link.exe");
+        if (!llvm::sys::fs::can_execute(linkPath))
+          C.getDriver().Diag(clang::diag::warn_drv_msvc_not_found);
+      } else {
+        C.getDriver().Diag(clang::diag::warn_drv_msvc_not_found);
+      }
+    }
 
 #ifdef _WIN32
     // When cross-compiling with VS2017 or newer, link.exe expects to have


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60094.194926.patch
Type: text/x-patch
Size: 1082 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190412/381eacf8/attachment.bin>


More information about the cfe-commits mailing list