Compile and link 32-bit program from Visual Studio 2008
I asked this same basic question yesterday, but had not got far enough to get a clear idea of the issue. Basically, this is the error I now get when building my app:
.\Debug\HotSync.obj : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'X86'
I assume this means that I'm compiling 64-bit object modules and then trying to link a 32-bit executable. So is this a matter of the compiler itself, or of an option given to the compiler? This project was previously a VC++ 2003 project, so has always been 32-bit.
I might mention that the only versions of cl.exe that I can find are in the amd64 and x86-amd64 subdirectories of VC\bin. I have to manually add one of these paths to the "VC++ 开发者_StackOverflowDirectories" list, but the results are the same for either.
My hosting PC is AMD running Windows 7 64-bit, but I would hope that I can still build programs that will run on XP. Anyone know how to do this?
A default installation of Visual Studio 2008 should have put an x86 cl.exe
and associated compiler binaries in:
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\
on a Win7 x64 system.
If you don't have a cl.exe
there (ie., 'above' the amd64
or x86_amd64
directories), then you might want to consider reinstalling Visual Studio.
Note that the compiler in the amd64
directory targets x64 systems and is itself built to run on x64 systems. The compiler in the x86_amd64
directory also targets x64 systems, but is itself an x86 binary (ie., it cross compiles to x64 from a x86 32-bit system).
You should also have a short-cut in the Visual Studio 2008 program group (or whatever that might be called in Win7):
"Microsoft Visual Studio 2008" | "Visual Studio Tools" | "Visual Studio 2008 Command Prompt"
that opens a command window that initially says:
Setting environment for using Microsoft Visual Studio 2008 x86 tools.
And running the cl
command there with no options should say something like:
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86
Again - if none of this is there for you, you need a reinstall.
Also, make sure that the project configurations for all of your projects involved in the build are set to Win32 and not x64.
Apparently the "problem" is that I only installed C++ since that's all that I plan on using. But for some reason the cl.exe that I need only gets installed as part of the C# installation. So go figger! Serves me right for trying to save clutter by not doing a full-full install.
精彩评论