LNK4068警告 + LNK1112错误导致在将环境变量 PreferredToolArchitecture 设置为“x64”时导致生成失败

LNK4068 warning + LNK1112 error leading to build failure when setting environment variable PreferredToolArchitecture to 'x64'

提问人:Bwmat 提问时间:7/6/2022 更新时间:7/6/2022 访问量:143

问:

05-Jul-2022 09:43:39           Lib:
05-Jul-2022 09:43:39    
05-Jul-2022 09:43:39             C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64_x86\Lib.exe /OUT:"..\Lib\w2012r2\vs2015\release32mt\KerberosSupport.lib" /NOLOGO /LTCG w2012r2\vs2015\release32mt\KSDialog.res
05-Jul-2022 09:43:39    
05-Jul-2022 09:43:39             w2012r2\vs2015\release32mt\KSKeytabOptionsDialog.obj
05-Jul-2022 09:43:39    
05-Jul-2022 09:43:39             w2012r2\vs2015\release32mt\KSDSNConfiguration.obj
05-Jul-2022 09:43:39    
05-Jul-2022 09:43:39             w2012r2\vs2015\release32mt\KSKrb5API_Windows.obj
05-Jul-2022 09:43:39    
05-Jul-2022 09:43:39             w2012r2\vs2015\release32mt\KSUtilities.obj
05-Jul-2022 09:43:39    
05-Jul-2022 09:43:39             w2012r2\vs2015\release32mt\KSKinitSupport.obj
05-Jul-2022 09:43:39    
05-Jul-2022 09:43:39             w2012r2\vs2015\release32mt\KSAuthenticatedCredentials.obj
05-Jul-2022 09:43:39    
05-Jul-2022 09:43:39             w2012r2\vs2015\release32mt\KSCredentialFactory.obj
05-Jul-2022 09:43:39    
05-Jul-2022 09:43:39             w2012r2\vs2015\release32mt\KSCredentials.obj
05-Jul-2022 09:43:39    
05-Jul-2022 09:43:39             w2012r2\vs2015\release32mt\KSGSSAPIWrapper.obj
05-Jul-2022 09:43:39    
05-Jul-2022 09:43:39             w2012r2\vs2015\release32mt\KSLocalCredentials.obj
05-Jul-2022 09:43:39    
05-Jul-2022 09:43:39             w2012r2\vs2015\release32mt\KSSecurity.obj
05-Jul-2022 09:43:39    
05-Jul-2022 09:43:39             w2012r2\vs2015\release32mt\KSSecurityContext.obj
05-Jul-2022 09:43:39    
05-Jul-2022 09:43:39         2>LINK : warning LNK4068: /MACHINE not specified; defaulting to X64 [C:\bamboo-agent-home\xml-data\build-dir\Drivers\DriverShared\KerberosSupport\Maintenance\10.1\Source\KerberosSupport_vs2015_NV.vcxproj]
05-Jul-2022 09:43:39    
05-Jul-2022 09:43:39         2>w2012r2\vs2015\release32mt\KSKeytabOptionsDialog.obj : fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64' [C:\bamboo-agent-home\xml-data\build-dir\Drivers\DriverShared\KerberosSupport\Maintenance\10.1\Source\KerberosSupport_vs2015_NV.vcxproj]

我担心的错误如上所示;问题的要点是项目文件没有为相关配置显式设置。TargetMachine<Lib>

在我们更改为 set 之前,它默认为 32 位构建工具,我想这决定了在LNK4068场景中使用的默认值PreferredToolArchitecture

我的问题是,根据 https://learn.microsoft.com/en-us/cpp/build/reference/running-lib?view=msvc-170

Usually, you don't need to specify /MACHINE. LIB infers the machine type from the .obj files. However, in some circumstances, LIB can't determine the machine type and issues an error message.

那个文档是错的吗?它看起来根本不看 obj 文件,只是使用 lib.exe 的位数,并且它使用默认值而不是出错。

另一个问题是,我能否以某种方式避免此问题,而不必更新依赖于此默认值的项目文件?从调用 msbuild 开始,我是否可以以某种方式注入逻辑以根据项目平台默认值?

visual-studio msbuild 链接器错误

评论

0赞 Jingmiao Xu-MSFT 7/7/2022
如果发生此类错误,请指定 /MACHINE。(learn.microsoft.com/en-us/cpp/build/reference/...
0赞 Bwmat 7/7/2022
@JingmiaoXu-MSFT我知道如何通过修改项目文件来修复它,我希望有一种方法可以在不这样做的情况下防止问题,因为有很多我无法控制的现有项目文件是用这个基础结构构建的

答: 暂无答案