How do I compile a 64-bit native C++ DLL in VS 2008?
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 typ开发者_JS百科e 'x64'
what do I change to make this go away?
UPD: Resolved, the problem source was surprisingly dumb, see my answer below.
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).
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.
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
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.
精彩评论