我有一个 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 时发生错误
注意: 我添加资源文件后才出现该错误。我不想将资源文件添加到静态库。
.vcxproj
条目解决了这个问题
<ItemGroup>
<ResourceCompile Include="MySampleLib.rc" />
</ItemGroup>
到
<ItemGroup Condition="'$(ConfigurationType)'!='StaticLibrary'">
<ResourceCompile Include="MySampleLib.rc" />
</ItemGroup>
这阻止了静态编译中资源文件的链接。
lib /def:libfftw3-3.def /MACHINE:x64