我有一个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
时发生错误注意:错误仅在我添加资源文件后出现。我不希望将资源文件添加到静态库中。
答案 0 :(得分:0)
我最后通过修改以下.vcxproj
条目
<ItemGroup>
<ResourceCompile Include="MySampleLib.rc" />
</ItemGroup>
到
<ItemGroup Condition="'$(ConfigurationType)'!='StaticLibrary'">
<ResourceCompile Include="MySampleLib.rc" />
</ItemGroup>
这阻止了静态编译中资源文件的链接。