C++ – linking problem: fatal error LNK1112: module machine type ‘x64’ conflicts with target machine type ‘X86’

clinkervisual studio

Im trying to run sample app from wxFreeChart library. After compilation on linking there is an error:

wxcode_msw28d_freechart.lib(wxfreechart_lib_xydataset.obj) : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'X86'

I tried to switch linker option\advanced\target machine to MachineX64 but it doesnt work.

Im using visual studio 2008, any suggestion ?

thanks for help

Best Answer

The error is explicit, you are trying to link libraries that were compiled with different CPU targets. An executable image can only contain pure x86 (32-bit) or pure x64 (64-bit) code. Mixing is not possible.

You change the target CPU by creating a new configuration for the project, only changing the linker setting isn't enough. Build + Configuration Manager, Active solution platform combo on upper right, choose New and select x64. That creates a new configuration with several modified project settings, most importantly the compiler that will be used.

Beware that prior to VS2010, the 64-bit compilers are not installed by default. If you don't see x64 in the platform combo then you'll need to re-run setup.exe and turn on the option to install the 64-bit compilers. Then also re-run any service pack installer you may have applied.

A possible approach with less pain points is to use the 32-bit version of the library.