[VS2010] 編譯64位靜態庫lib提示fatal error LNK1112: module machine type 'x64' conflicts等錯誤的解決方案
環境
Win7 x64
Visual Studio 2010
程式寫完,本想匯出dll(x64)、lib (x64),在動態連結庫dll下編譯成功。
但是在編譯靜態庫lib時,出錯了
報錯如下:
1>—— Build started: Project: EditAlgoTestFrameWork, Configuration: Release x64 ——
1>Build started 1/17/2018 11:32:37 AM.
1>InitializeBuildStatus:
1> Creating “x64\Release\EditAlgoTestFrameWork.unsuccessfulbuild” because “AlwaysCreate” was specified.
1>ClCompile:
1> All outputs are up-to-date.
1>ResourceCompile:
1> All outputs are up-to-date.
1>Lib:
1> All outputs are up-to-date.
1>LINK : warning LNK4068: /MACHINE not specified; defaulting to X86
1>x64\Release\Test.obj : fatal error LNK1112: module machine type ‘x64’ conflicts with target machine type ‘X86’
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.20
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
原因
由於專案預設 /MACHINE屬性值為X86,故在編譯lib(x64)時,需要顯式指定其值為X64
解決方案
專案右鍵屬性(Properties) –> 配置屬性(Configuration Properties) –> 庫管理器(Librarian) –> 命令列(Command Line) –> 其他選項(additional Options) 指定/MACHINE值為X64:
/MACHINE:X64
儲存並重新編譯即可通過。