views:

272

answers:

4

I'm trying to port a native ATL C++ in-proc COM server to 64 bit in Visual Studio 2008. I've opened the Configuration Manager, added "x64" platform. Now I have 6 configurations - 3 for Win32 that compile and link fine and 3 for x64 that compile fine, but make the linker emit the following error:

\Debug64\Objects\common.obj : fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'

what do I change to make this go away?

UPD: Resolved, the problem source was surprisingly dumb, see my answer below.

A: 

Are you sure the target machine for common.obj is x86? Because the linker is telling you it is not. Check in solution->properties->configuration that Platform really is x64, and also set it in project->properties->linker->advanced->target machine. and rebuild.

stijn
What exactly do I check to ensure that the target machine for that .obj file is right?
sharptooth
did you try both things I mentioned? Btw if you want to check manually, open the file in a text or hex editor and look for a line containng '/manifestdependency' or 'processorArchitecture' it will tell what platfrom it was compiled for. Or easier, if you let the linker emit map files, the addresses will all be 64bits long instead of 32.
stijn
Yes, there's a problem: /manifestdependency:"type='win32' name='Microsoft.VC90.CRT' version='9.0.21022.8' processorArchitecture='x86' but how do I fix that?
sharptooth
well, did you already try what I and Joakim suggested??
stijn
Yes, the preprocessor defs and the linker settings are set up right. And I don't use MIDL anywhere in the project.
sharptooth
in that caes: I'm clueless; unless: do you have per-file settings for compilation? Open your vcproj file in a text editor and check if there's any <fileconfiguration> block for the file that produces common.obj (I'd guess that would be common.cpp)?
stijn
+1  A: 

Did you install the "x64 compiler and tools" component during the visual studio installation?

Also check these settings: (copied from msdn)

  • /MACHINE (Specify Target Platform) is set to /MACHINE:IA64 or /MACHINE:X64.

  • Register Output is turned OFF. For more information, see Linker Property Pages.

  • Target Environment is set to /env x64 or /env ia64. For more information, see MIDL Property Pages: General.

  • Validate Parameters is cleared and reset to the default value. For more information, see MIDL Property Pages: Advanced.

  • If Debug Information Format was set to /ZI in the Win32 project configuration, then it is set to /Zi in the 64-bit project configuration. For more information, see /Z7, /Zi, /ZI (Debug Information Format).

  • Values of WIN32 are replaced by WIN64 for /D (Preprocessor Definitions).

Joakim Karlsson
Visual C++ does not set all what is needed for x64 compilation. IMO, the most important points are the first (found in Configuration properties/Linker/Advanced) and the last (found in Configuration properties/C/C++/Preprocessor definitions).
RaphaelSP
A: 

A common problem is failing to use a Debug64 and Release64 directory. Exact names don't matter that much, but if you end up mixing 32 and 64 bits .objs, .libs or .dlls in a single directory, the linker will have issues.

A quick way to determine if this contributed is by doing a clean build. If the link problem doesn't disappear, then mixing of intermediate binaries was not the cause

MSalters
A: 

Well, the real reason was surprisingly simple. We don't use a .cmd file shipped with VS for setting the environment variables but instead use our own equivalent .cmd file. That file set the %PATH% variable for 32-bit cl.exe and that's exactly why C++ source was compiled with a 32-bit compiler. The soluton is to iether use the .cmd for x64 compilation shipped with VS or to craft a custom .cmd file setting %PATH% appropriately.

sharptooth