[cfe-dev] Compiling a simple Win32 program

Nikola Smiljanic popizdeh at gmail.com
Thu Jun 7 08:50:16 PDT 2012


On Thu, Jun 7, 2012 at 3:12 PM, Anton Korobeynikov
<anton at korobeynikov.info>wrote:

> 1. Please follow LLVM style guidelines (no tabs, etc.)
>

Sorry about that


> 2. Please use Support/Path library
>
>
Fixed, but there's some code in ToolChains.cpp that handles paths the way I
did.


>
> You should check & use target arch.
>
>
What I have now kinda works. But the problem is that I'm not interested in
Clang's default triple, I'm interested if the OS is 32bit or 64bit. So if I
have a 32bit Clang running on my Windows x64 and I'm targeting x64, it will
use a cross tools which is wrong! How can I detect this?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120607/19e218f6/attachment.html>
-------------- next part --------------
Index: lib/Driver/WindowsToolChain.cpp
===================================================================
--- lib/Driver/WindowsToolChain.cpp	(revision 158139)
+++ lib/Driver/WindowsToolChain.cpp	(working copy)
@@ -16,6 +16,7 @@
 #include "clang/Driver/Options.h"
 #include "clang/Basic/Version.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/Host.h"
 #include "llvm/Support/Path.h"
 
 // Include the necessary headers to interface with the Windows registry and
@@ -25,6 +26,8 @@
   #define NOGDI
   #define NOMINMAX
   #include <Windows.h>
+
+  static bool getVisualStudioDir(std::string &path);
 #endif
 
 using namespace clang::driver;
@@ -33,6 +36,18 @@
 
 Windows::Windows(const Driver &D, const llvm::Triple& Triple)
   : ToolChain(D, Triple) {
+  std::string path;
+  if (getVisualStudioDir(path)) {
+    llvm::sys::Path P(path);
+    P.appendComponent("VC");
+    P.appendComponent("bin");
+    llvm::Triple Default(llvm::sys::getDefaultTargetTriple());
+    if (Default.isArch32Bit() && Triple.isArch64Bit())
+      P.appendComponent("\\x86_amd64");
+    else if (Default.isArch64Bit() && Triple.isArch64Bit())
+      P.appendComponent("\\amd64");
+    getProgramPaths().push_back(P.str());
+  }
 }
 
 Tool &Windows::SelectTool(const Compilation &C, const JobAction &JA,


More information about the cfe-dev mailing list