我使用CUDA (vc++, Visual studio 2008sp1)来调试FEM程序。由于cuda的不足,该程序只能在Win32平台上运行。我认为链接的库文件都是在x86平台上编译的,但是当我编译它时,我得到了错误消息
致命错误LNK1112:模块机类型“x64”与目标机类型“X86”冲突。
我曾尝试将该平台转换为x64,但没有成功。请告诉我:什么是“模块机类型”,什么是“目标机类型”?我怎样才能克服它呢?
我使用CUDA (vc++, Visual studio 2008sp1)来调试FEM程序。由于cuda的不足,该程序只能在Win32平台上运行。我认为链接的库文件都是在x86平台上编译的,但是当我编译它时,我得到了错误消息
致命错误LNK1112:模块机类型“x64”与目标机类型“X86”冲突。
我曾尝试将该平台转换为x64,但没有成功。请告诉我:什么是“模块机类型”,什么是“目标机类型”?我怎样才能克服它呢?
当前回答
除了C Johnson的清单之外,我还要补充以下几点:
检查在Visual Studio: 项目属性->配置属性-> link ->命令行。
“附加选项”不应该包含/machine:X86
我有这样的键,由CMake输出生成:CMake生成x86项目,然后我通过Visual Studio 2010中的配置管理器添加了x64平台-除了链接器命令行,单独指定/machine: x86之外,新平台的一切都创建得很好。
其他回答
当我遇到这个令人抓狂的问题时,我写了一篇关于这个问题的博客文章,并最终将我的系统恢复到正常工作状态。
以下是需要检查的事项,按顺序:
Check your properties options in your linker settings at: Properties > Configuration Properties > Linker > Advanced > Target Machine. Select MachineX64 if you are targeting a 64 bit build, or MachineX86 if you are making a 32 bit build. Select Build > Configuration Manager from the main menu in visual studio. Make sure your project has the correct platform specified. It is possible for the IDE to be set to build x64 but an individual project in the solution can be set to target win32. So yeah, visual studio leaves a lot of rope to hang yourself, but that's life. Check your library files that they really are of the type of platform are targeting. This can be used by using dumpbin.exe which is in your visual studio VC\bin directory. use the -headers option to dump all your functions. Look for the machine entry for each function. it should include x64 if it's a 64 bit build. In visual studio, select Tools > Options from the main menu. select Projects and Solutions > VC++ Directories. Select x64 from the Platform dropdown. Make sure that the first entry is: $(VCInstallDir)\bin\x86_amd64 followed by $(VCInstallDir)\bin.
一旦我完成了第4步,一切都恢复正常了。问题是我在我所有的项目中都遇到了这个问题,我想编译一个64位的目标。
对于一些使用命令提示符(dos提示符)的用户 这可能会有帮助:
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" --help
Error in script usage. The correct usage is:
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" [option]
or
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" [option] store
or
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" [option] [version number]
or
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" [option] store [version number]
where [option] is: x86 | amd64 | arm | x86_amd64 | x86_arm | amd64_x86 | amd64_arm
where [version number] is either the full Windows 10 SDK version number or "8.1" to use the windows 8.1 SDK
:
The store parameter sets environment variables to support
store (rather than desktop) development.
:
For example:
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_arm store
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64 10.0.10240.0
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_arm store 10.0.10240.0
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64 8.1
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64 store 8.1
:
Please make sure either Visual Studio or C++ Build SKU is installed.
如果你这样做:
CL "%1%2%3" /EHsc /链接user32。自由Gdi32。自由Winmm。自由comctl32。自由*。obj /子系统:CONSOLE /MACHINE:x86
你必须取消*。obj之前;为了避免混淆链接器与64和32位对象从以前的编译遗留下来?
今天我就遇到了这种情况,因为我在x86模式下添加了一个库目录,并意外地删除了继承的目录,使它们变成了硬编码。 然后切换到x64后,我的vc++目录仍然读:
“... (VC_LibraryPath_x86美元);(WindowsSDK_LibraryPath_x86美元);”
而不是_x64。
vcxproj文件可能包含“MACHINE:i386” 用编辑器编辑vcxproj文件。把它拿掉!
除了C Johnson的清单之外,我还要补充以下几点:
检查在Visual Studio: 项目属性->配置属性-> link ->命令行。
“附加选项”不应该包含/machine:X86
我有这样的键,由CMake输出生成:CMake生成x86项目,然后我通过Visual Studio 2010中的配置管理器添加了x64平台-除了链接器命令行,单独指定/machine: x86之外,新平台的一切都创建得很好。