With all my confusion about 32- vs. 64-bits in C# and C++, I wanted to build some C++ exes and dlls in 64 bits to work out how everything fit together. But it took me a while to figure out how to do this in Visual Studio. For a C# project, there is an easy-to-find option under
Platform Target, with choices called
x64. But there is nothing quite so evident among the properties for a C++ project.
To build a 64-bit version for your C++ app, you should open the Properties dialog and then click the
Configuration Manager button in the upper-right corner. Then select the
Active Solution Platform dropdown menu, and choose
x64, and request to copy over the old Win32 properties. Now you can build your project for either 32 or 64 bits. Visual Studio maintains separate properties for each. You use the Configuration Manager to set the “Active” platform, which is what actually gets built, but you can adjust the properties of either platform using the
Platform dropdown at the top of the properties dialog.
Once you’ve enabled both platforms for your project, make sure x64 is set as the active target, and take at look at the x64 properties under
Linker:Advanced. You should see one called
Target Machine, set to
MachineX64 (/MACHINE:X64). Under the Win32 version, this read
MachineX86 (/MACHINE:X86), but Visual Studio should have flipped it automatically when you created the x64 target. If not, set it correctly now.
Note that if you have a mismatch between the Platform and the linker’s setting, you’ll get a build error like this:
fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'So you need MachineX86 with a Win32 platform, and MachineX64 with the x64 platform.
Now you should be able to build both 32- and 64-bit versions of your app!blog comments powered by Disqus Prev: DLL Inspector Next: Calling a C++ DLL from C#