title: How do you compile 32-bit and 64-bit applications at the same time in Visual Studio for C/C++ in a makefile?
body: <p>My question is similar to <a href="https://stackoverflow.com/questions/145803/targeting-both-32bit-and-64bit-with-visual-studio-in-same-solution-project">Targeting both 32bit and 64bit with Visual Studio in same solution/project</a>.</p>
  
  <p>However, I need to accomplish this in a GNUmakefile.</p>
  
  <p>For instance, if i wanted to cross compile 32 and 64 bit applications via <code>gcc</code>, I can use the <code>-m32</code> &amp; <code>-m64</code> flags during compilation and linking.  This method is different for visual studio because I have to run <code>vcvarsall.bat x86</code> to compile for 32 bit and <code>vcvarsall.bat x64</code> for 64 bit to setup my environment for compilation.</p>
  
  <pre><code>all: foo.exe foo64.exe
  
  foo.exe: obj32/foo.o
      link.exe /MACHINE:X86 $(OTHER_FLAGS) /out:$@ $^
  
  foo64.exe: obj64/foo.o
      link.exe /MACHINE:X64 $(OTHER_FLAGS) /out:$@ $^
  
  obj32/foo.o: foo.c
      cl.exe $(CFLAGS) $(INCLUDE_DIRS) /Fo$@ /c $&lt;
  
  obj64/foo.o: foo.c
      cl.exe $(CFLAGS) $(INCLUDE_DIRS) /Fo$@ /c $&lt;
  </code></pre>
  
  <p>The above sample would not work because you need to rerun the vcvarsall.bat environment script in between compilation of 32 and 64 bit.  If I try to compile the above sample makefile when after running vcvarsall.bat x86, I would get this error when trying to link the 64 bit executable:</p>
  
  <pre><code> fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'
  </code></pre>
  
  <p><strong>Is there a way we can accomplish building both 32 and 64 bit applications with one invocation of make?</strong></p>