【问题标题】:msbuild - static lib compilation failed after adding resource file to projectmsbuild - 将资源文件添加到项目后静态库编译失败
【发布时间】:2017-05-21 21:00:03
【问题描述】:

我有一个 C++ 库,它被编译为动态和静态库。最近我将资源版本文件添加到源。动态库编译工作正常,但是对于 64 位目标静态库编译开始失败,并出现以下错误:

LINK : warning LNK4068: /MACHINE not specified; defaulting to X86

 x64\Release\dllmain.obj : fatal error LNK1112: module machine type 'x64' conflicts with target machine type 'X86'

以下是我的编译脚本:

@ECHO OFF
call "%VS140COMNTOOLS%"\\vsvars32.bat
SET SourceDir=D:\Projects\MySampleLib
SET TargetDir=D:\Projects\Packages

ECHO 32 bit MySampleLib .LIB compilation VS2010

msbuild.exe %SourceDir%\MySampleLib\MySampleLib.vcxproj /t:Clean;Rebuild /p:Configuration=Release;Platform=Win32;ConfigurationType=StaticLibrary;PlatformToolset=v100


ECHO 64 bit MySampleLib .LIB compilation VS2010

msbuild.exe %SourceDir%\MySampleLib\MySampleLib.vcxproj /t:Clean;Rebuild /p:Configuration=Release;Platform=x64;ConfigurationType=StaticLibrary;PlatformToolset=Windows7.1SDK

Lib.exe 命令尝试链接 MySampleLib.res

时发生错误

注意:这个错误是我添加资源文件后才出现的。我不想将资源文件添加到静态库中。

【问题讨论】:

  • 您不能将资源添加到静态库。同样由于静态库没有被链接(链接发生在最终的可执行文件被构建时),无论你为调用静态库的链接器所做的一切都是你问题的开始。 Lib.exe 命令是库管理器而不是链接器。
  • @RichardCritten 我不想将资源文件添加到静态库中。我只为动态版本添加了它们。在我的编译脚本中我也没有做任何事情。
  • 您确定这与资源有任何关系吗?错误似乎很清楚:您正在编译 64 位目标文件(因此 module 机器类型 'x64' 提到)但不要将 /MACHINE:x64 传递给链接器(因此 /MACHINE 未指定;默认为 X86),因此它尝试链接 32 位目标文件。这不起作用,因为它给出了 64 位目标文件。

标签: c++ visual-studio-2010 msbuild


【解决方案1】:

我终于通过修改以下.vcxproj 条目解决了这个问题

<ItemGroup>
    <ResourceCompile Include="MySampleLib.rc" />
</ItemGroup>

<ItemGroup Condition="'$(ConfigurationType)'!='StaticLibrary'">
    <ResourceCompile Include="MySampleLib.rc" />
</ItemGroup>

这阻止了静态编译中资源文件的链接。

【讨论】:

    猜你喜欢
    • 2017-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-18
    • 1970-01-01
    • 1970-01-01
    • 2010-10-20
    相关资源
    最近更新 更多