My question is similar to Targeting both 32bit and 64bit with Visual Studio in same solution/project.
However, I need to accomplish this in a GNUmakefile.
For instance, if i wanted to cross compile 32 and 64 bit applications via gcc
, I can use the -m32
& -m64
flags during compilation and linking. This method is different for visual studio because I have to run vcvarsall.bat x86
to compile for 32 bit and vcvarsall.bat x64
for 64 bit to setup my environment for compilation.
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 $<
obj64/foo.o: foo.c
cl.exe $(CFLAGS) $(INCLUDE_DIRS) /Fo$@ /c $<
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:
fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'
Is there a way we can accomplish building both 32 and 64 bit applications with one invocation of make?