2
votes

I am working on a 32bit environment. I have a solution containing a set of C# projects and a set of VC++ unmanaged projects.For All the C# projects build platform have been set to "Any CPU" and for the VC++ projects it is Win32. We are migrating to 64 bit platform. Now my questions are

1) Can i convert my 32bit VC++ Dlls to 64 bit in my 32 bit environment ?

2) whether there is a way i can set the platform for the VC++ projects also to something like "Any CPU" ?

3) I opened the Configuration Manager under the Build menu in VS2008. Set the Active Solution platform to Any CPU ( this i didnt change it previously set to this platform only) , then i set the platform of VC++ projects to X64. Now i cleaned up the solution and tried re-building the solution. The VC++ projects were not getting built and hence the C# projects having references to the VC++ projects were also not built. I tried independently building the VC++ project and i got this error : "fatal error LNK1112: module machine type X86 conflicts with target machine type x64"

Any ideas and suggestions are greatly appreciated!

Thanks, Keerti Somasundaram

2
Don't try to port to 64-bit if you don't have a 64-bit machine to test on.bdonlan

2 Answers

7
votes

Can i convert my 32bit VC++ Dlls to 64 bit in my 32 bit environment ?

You can certainly use a 32-bit system to compile code for a 64-bit system if you have the 64-bit compilers available (some editions of some versions of Visual Studio don't include 64-bit compilers etc). Since you were able to set the target platform to x64 and compile your code it sounds like you do have the compilers available.

Testing and debugging is harder if you do your compiles on a 32-bit system. Obviously you have to run your tests on an x64 system, so now you are forced to use the remote debugger.

whether there is a way i can set the platform for the VC++ projects also to something like "Any CPU" ?

That wouldn't really make sense for native C++. A native code dll is very definitely either a 32-bit or a 64-bit code file. Managed code can support "Any CPU" because the JIT takes care of compiling IL into the actual platform op codes, so it can translate to x86 or to x64 as appropriate.

The VC++ projects were not getting built

Use the Build menu's Configuration manager command to check your build configuration. You may find that the configuration has an entry for your VC++ Dll project for the x64 platform but that the Build checkbox is unchecked.

fatal error LNK1112: module machine type X86 conflicts with target machine type x64

The linker is telling you that the target for the linked file is x64 (which is what you want) but the module (file) being input to the linker was built for x86 so it conflicts with that target. What you do to fix this problem depends on what the module is.

If you are getting this error with an obj file created by compiling one of your project's cpp files then the problem is that your project is compiling that cpp file for x86 instead of x64.

More likely you are getting this error for a LIB file (or some other file) being linked to your project - for example a LIB file from some SDK. In that case the fix is probably to change the project properties so you use the correct (i.e., x64) LIB file. Some SDKs use different file names for 32 and 64 bit versions of a LIB file. Others use the same name for the LIB file but store the x86 and x64 versions in different directories.

A good place to start looking would be Project | Properties | Linker. On the General tab there's an "Additional Library Directories" field. Any entry in there should probably point to different directories for x86 and x64 platforms (unless a particular directory is used to hold both x86 and x64 files). On the Input tab there's an "Additional Dependencies" field. Any entries in there should probably be the same for all platforms (unless different file names are used to distinguish x86 and x64 files from each other).

Another place to check is Tools | Options | Projects and Solutions | VC++ Directories. These settings list various directories that are searched for certain types of files. There are separate lists for each platform. In your case you'd want to check the "Library files" list. For the x64 platform you'd want to make sure that the "Libraries files" list specified directories that contained x64 versions of library files.

3
votes

In terms of fixing this problem for myself, I found the following link very useful.

http://msdn.microsoft.com/en-us/library/9yb4317s.aspx

For me, I was trying to convert a 32 bit VC++ VS2010 application into a 64 bit application.

I was getting errors such as

link warning lnk4068 /machine not specified defaulting to x86

or

fatal error lnk1112 module machine type 'x86' conflicts with target machine type 'x64'

I followed advice from various other websites but needed the information regarding the targetted /MACHINE setting.

For me, setting this worked a treat:

Project Settings \ Configuration Properties \ Librarian \ General \ Target Machine

Old value: blank (which defaults to x86) New Value: MachineX64 (/MACHINE:X64)

Hope this helps someone else.