msbuild - 将资源文件添加到项目后静态库编译失败

问题描述 投票:0回答:2

我有一个 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 时发生错误

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

c++ visual-studio-2010 msbuild
2个回答
2
投票
我终于通过修改以下

.vcxproj

条目解决了这个问题

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

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

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


0
投票
按照指南在终端中构建库时,我通过指定 /MACHINE 类型消除了错误。

lib /def:libfftw3-3.def /MACHINE:x64
    
© www.soinside.com 2019 - 2024. All rights reserved.