C++ 链接问题:致命错误 LNK1112:模块机器类型“x64”与目标机器类型“X86”冲突

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2849517/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 11:16:07  来源:igfitidea点击:

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

c++visual-studiolinker

提问by gruber

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

我试图从 wxFreeChart 库运行示例应用程序。编译链接后出现错误:

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.

我试图将链接器选项\高级\目标机器切换到 MachineX64,但它不起作用。

Im using visual studio 2008, any suggestion ?

我正在使用 Visual Studio 2008,有什么建议吗?

thanks for help

感谢帮助

回答by Hans Passant

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.

错误很明显,您正在尝试链接使用不同 CPU 目标编译的库。可执行映像只能包含纯 x86(32 位)或纯 x64(64 位)代码。混合是不可能的。

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.

您可以通过为项目创建新配置来更改目标 CPU,仅更改链接器设置是不够的。构建 + 配置管理器,右上角的活动解决方案平台组合,选择新建并选择 x64。这将创建一个具有多个修改项目设置的新配置,最重要的是将使用的编译器。

Beware that prior to VS2010, the 64-bit compilers are notinstalled 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.

请注意,在 VS2010 之前,默认情况下不会安装64 位编译器。如果在平台组合中没有看到 x64,则需要重新运行 setup.exe 并打开安装 64 位编译器的选项。然后还重新运行您可能已应用的任何服务包安装程序。

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

一种具有较少痛点的可能方法是使用该库的 32 位版本。

回答by l00g33k

I bumped into this too and found a solution.

我也遇到了这个问题并找到了解决方案。

First on how I got into this problem. I have a project which builds in x86. Then I used the Configuration Manager to add x64, and I hit this problem.

首先谈谈我是如何陷入这个问题的。我有一个在 x86 中构建的项目。然后我使用配置管理器添加x64,我遇到了这个问题。

By looking at BuildLog.htmcarefully, I saw both of these listed as linker options:

通过BuildLog.htm仔细查看,我看到这两个都被列为链接器选项:

/MACHINE:X64  
/machine:X86 

I could not find anywhere in the Property Pages dialog where I could change this, so I opened up the .vcprojfile and looked for the appropriate line and changed it to:

我在“属性页”对话框中找不到可以更改此设置的任何位置,因此我打开.vcproj文件并查找相应的行并将其更改为:

AdditionalOptions=" /STACK:10000000 /machine:x64 /debug"

and problem solved.

并解决了问题。

回答by Joseph

Go to project properties-> configuration properties -> Librarian Set Target Machine to MachineX64 (/MACHINE:X64)

转到项目属性-> 配置属性-> 图书管理员将目标机器设置为 MachineX64 (/MACHINE:X64)

回答by rogerdpack

In my case it appears it was because I had "copied settings" from a 32-bit to a new configuration (64 bit) and it hadn't updated the libraries. Odd.

就我而言,这似乎是因为我将 32 位的“设置”“复制”到了新的配置(64 位),并且它没有更新库。奇怪的。

1>MSVCRTD.lib(ti_inst.obj) : fatal error LNK1112: module machine type ‘X86' conflicts with target machine type ‘x64'

1>MSVCRTD.lib(ti_inst.obj):致命错误 LNK1112:模块机器类型“X86”与目标机器类型“x64”冲突

this meant “your properties -> VC++ Directories -> Library Directories” is pointing to a directory that has 32 bit libs built in it. Fix somehow!

这意味着“您的属性 -> VC++ 目录 -> 库目录”指向一个内置 32 位库的目录。以某种方式修复!

In my case http://social.msdn.microsoft.com/Forums/ar/vcgeneral/thread/c747cd6f-32be-4159-b9d3-d2e33d2bab55

在我的情况下http://social.msdn.microsoft.com/Forums/ar/vcgeneral/thread/c747cd6f-32be-4159-b9d3-d2e33d2bab55

ref: http://betterlogic.com/roger/2012/02/visual-studio-2010-express-64-bit-woe

参考:http: //betterlogic.com/roger/2012/02/visual-studio-2010-express-64-bit-woe

回答by hab

Since the problem is due to the difference in compilation and target machine specifications (x86 & x64) Follow the steps below:

由于问题是由于编译和目标机器规格(x86 & x64)不同造成的,请按照以下步骤操作:

  1. Open the C++ project that you want to configure.
  2. Choose the Configuration Manager button to open the Configuration Manager dialog box.
  3. In the Active Solution Platform drop-down list, select the option to open the New Solution Platform dialog box.
  4. In the Type or select the new platform drop-down list, select a 64-bit platform.
  1. 打开要配置的 C++ 项目。
  2. 选择“配置管理器”按钮以打开“配置管理器”对话框。
  3. 在活动解决方案平台下拉列表中,选择打开新建解决方案平台对话框的选项。
  4. 在类型或选择新平台下拉列表中,选择 64 位平台。

This solved my problem.

这解决了我的问题。

回答by Thomas

Try changing every occurence of .\Release into .\x64\Release in the x64 properties. At least this worked for me...

尝试在 x64 属性中将 .\Release 的每次出现更改为 .\x64\Release。至少这对我有用......

回答by JoeC

Thanks for the answers guys. My problem was that I changed a x64 solution in Visual Studio to 32 bit in the Configuration Manager only. I ended up just creating a new solution as 32 bit and then copying my C++ code and this error was gone. I think l00g33k and RogerAttrill's suggestions may have been the solution, but mine worked, too.

谢谢各位的回答。我的问题是我仅在配置管理器中将 Visual Studio 中的 x64 解决方案更改为 32 位。我最终只是创建了一个 32 位的新解决方案,然后复制了我的 C++ 代码,这个错误就消失了。我认为 l00g33k 和 RogerAttrill 的建议可能是解决方案,但我的也奏效了。

回答by Crawl.W

Recently,I also encountered this problem. That's because I used qt(x64) in vs win32. If you want to use qt application x64, you could choose vs x64--as the above. If you want to use win32and perhaps you haven't,you need to download qt(32bit),then correctly set your enviroment, such as the libdirectory, etc.(note: maybe you are is old set in x64(other version), if you convert your win32 or x64 into another, Additional Dependenciesincludes the old directory!)

最近,我也遇到了这个问题。那是因为我x64在 vs 中使用了 qt( ) win32。如果你想使用 qt application x64,你可以选择 vs x64-- 如上所述。如果你想使用win32,也许你还没有,你需要下载qt( 32bit),然后正确设置你的环境,例如lib目录等(注意:x64(other version)如果你转换你的win32或x64 到另一个,Additional Dependencies包括旧目录!)

回答by Crawl.W

This problem has nothing to do with the linker, so modifying it's setting won't affect the outcome. You're getting this because I assume you're trying to target x86 but for one reason or another wxcode_msw28d_freechart.lib is being built as an x64 file.

这个问题与链接器无关,所以修改它的设置不会影响结果。你得到这个是因为我假设你试图以 x86 为目标,但出于某种原因或另一个 wxcode_msw28d_freechart.lib 被构建为 x64 文件。

Try looking at wxcode_msw28d_freechart.lib and whatever source code it derives from. Your problem is happening there. See if there are some special build steps that are using the wrong set of tools (x64 instead of x86).

尝试查看 wxcode_msw28d_freechart.lib 及其派生的任何源代码。你的问题发生在那里。查看是否有一些特殊的构建步骤使用了错误的工具集(x64 而不是 x86)。

回答by Kevin Afanasiff

building on these answers - i also had to modify an X86 reference under Librarian -> Command Line -> Additional Options (for the x64 Platform)

基于这些答案 - 我还必须在 Librarian -> Command Line -> Additional Options (for the x64 Platform) 下修改 X86 参考