【发布时间】:2011-08-14 00:56:48
【问题描述】:
我的问题类似于Targeting both 32bit and 64bit with Visual Studio in same solution/project。
但是,我需要在 GNUmakefile 中完成此操作。
例如,如果我想通过 gcc 交叉编译 32 位和 64 位应用程序,我可以在编译和链接期间使用 -m32 和 -m64 标志。这种方法对于 Visual Studio 是不同的,因为我必须运行 vcvarsall.bat x86 来编译 32 位和 vcvarsall.bat x64 来编译 64 位来设置我的编译环境。
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 $<
上面的示例不起作用,因为您需要在 32 位和 64 位编译之间重新运行 vcvarsall.bat 环境脚本。如果我在运行 vcvarsall.bat x86 后尝试编译上述示例 makefile,则在尝试链接 64 位可执行文件时会出现此错误:
fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'
有没有一种方法可以通过一次 make 调用同时构建 32 位和 64 位应用程序?
【问题讨论】:
标签: visual-studio visual-studio-2010 gnu-make