diff --git a/driver/linker.cpp b/driver/linker.cpp index 114023ac44..39297aa8ec 100644 --- a/driver/linker.cpp +++ b/driver/linker.cpp @@ -492,6 +492,10 @@ static int linkObjToBinaryGcc(bool sharedLib, bool fullyStatic) { static int linkObjToBinaryMSVC(bool sharedLib) { Logger::println("*** Linking executable ***"); +#ifdef _WIN32 + windows::setupMsvcEnvironment(); +#endif + const std::string tool = "link.exe"; // build arguments @@ -592,10 +596,6 @@ static int linkObjToBinaryMSVC(bool sharedLib) { } logstr << "\n"; // FIXME where's flush ? -#ifdef _WIN32 - windows::setupMsvcEnvironment(); -#endif - // try to call linker return executeToolAndWait(tool, args, global.params.verbose); } @@ -630,6 +630,11 @@ int createStaticLibrary() { if (useInternalArchiver) { tool = isTargetMSVC ? "llvm-lib.exe" : "llvm-ar"; } else { +#ifdef _WIN32 + if (isTargetMSVC) + windows::setupMsvcEnvironment(); +#endif + tool = getProgram(isTargetMSVC ? "lib.exe" : "ar", &ar); } @@ -708,11 +713,6 @@ int createStaticLibrary() { } #endif -#ifdef _WIN32 - if (isTargetMSVC) - windows::setupMsvcEnvironment(); -#endif - // try to call archiver return executeToolAndWait(tool, args, global.params.verbose); } diff --git a/driver/tool.cpp b/driver/tool.cpp index f9075ddc1e..8d54b21460 100644 --- a/driver/tool.cpp +++ b/driver/tool.cpp @@ -209,7 +209,7 @@ int executeAndWait(const char *commandLine) { return exitCode; } -bool setupMsvcEnvironment() { +bool setupMsvcEnvironmentImpl() { if (getenv("VSINSTALLDIR")) return true; @@ -311,6 +311,13 @@ bool setupMsvcEnvironment() { return haveVsInstallDir; } +bool setupMsvcEnvironment() { + const bool success = setupMsvcEnvironmentImpl(); + if (!success) + warning(Loc(), "no Visual C++ installation detected"); + return success; +} + } // namespace windows #endif // _WIN32