如何在 Visual Studio for C/C 中同时编译 32 位和 64 位应用程序?在 makefile 中?
我的问题类似于 针对 32 位以及在同一解决方案/项目中使用 Visual Studio 的 64 位。
但是,我需要在 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'
是否有一种方法可以同时构建 32 位和 64 位应用程序调用make?
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 lt;
obj64/foo.o: foo.c
cl.exe $(CFLAGS) $(INCLUDE_DIRS) /Fo$@ /c lt;
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不必必须使用 vcvar。这些是用于在一种平台环境或另一种平台环境中构建的便捷脚本。通过显式调用适当的命令并向它们传递适当的选项,您可以编译两者,而无需调用两个不同的批处理文件。
以下是将“foo”程序示例编写为 GNU makefile 的一种方法:
这仍然假设 vcvarsall.bat x86 已预先运行,但需要更多工作,甚至可以消除这些工作。
You don't have to use vcvars. Those are convenience scripts for building in one platform environment or the other. By explicitly invoking the proper commands and passing them the appropriate options you can compile both without having to invoke two different batch files.
Here is one way to write your "foo" program example as a GNU makefile:
This still assumes
vcvarsall.bat x86
was run beforehand but with more work even that can be eliminated.