1. 程式人生 > >zlib編譯不過(Error A2070)解決方法(轉)

zlib編譯不過(Error A2070)解決方法(轉)

endif api 位置 round instr a20 letter courier new

原文轉自 http://dearymz.blog.163.com/blog/static/2056574200871010027435/

1、zlib是個很牛的東東,從http://www.zlib.net/可以獲取到源碼,但在VS2008下編譯會報錯:error PRJ0019: 某個工具從以下位置返回了錯誤代碼: "Assembling...", 翻開BuildLog.htm查看其編譯命令行ml.exe /nologo /c /coff /Cx /Zi /Fo".\Win32_DLL_ASM_Debug\inffas32.obj" "前面是我的路徑\zlib123\contrib\masmx86\inffas32.asm", 然後將該命令放在"VS2008命令行提示"控制臺下運行,報錯的具體情況就很明顯啦:

E:提示符>ml.exe /nologo /c /coff /Cx/Zi /Fo".\Win32_DLL_ASM_Debug\inffas32.obj" "我的路徑\zlib123\contrib\masmx86\inffas32.asm"
Assembling: E:\開源項目\壓縮\zlib 1.2.3\zlib123\contrib\masmx86\inffas32.asm
我的路徑\zlib123\contrib\masmx86\inffas32.asm(647) : error A2070:invalid instruction operands
我的路徑\zlib123\contrib\masmx86\inffas32.asm(649) : error A2070:invalid instruction operands
我的路徑\zlib123\contrib\masmx86\inffas32.asm(663) : error A2070:invalid instruction operands
我的路徑\zlib123\contrib\masmx86\inffas32.asm(720) : error A2070:invalid instruction operands

查下MSDN:

ML Nonfatal Error A2070

invalid instruction operands

One or more operands were not valid for the instruction with which they were specified.

(這個解釋基本屬於廢話)

上網一查,發現別人也遇到相同的問題:http://svn.haxx.se/dev/archive-2005-11/0942.shtml。原因在於

It (Microsoft Macro Assembler 8.0, included with Visual C++ 2005 Express ) refuses to assemble a MOVD instruction with a memory operand with an implied size, and requires that "dword ptr" prefix the memory operand.

微軟說這是by design,不是bug:

http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=6306f7dc-2cc2-4591-bd60-5d802178fdfa

解決辦法是把inffas32.asm中的4處出錯的類似

movd mm4, [esp+0]

的匯編代碼,添加dword ptr修飾符,改為

movd mm4,dword ptr [esp+0]

這樣就能順利編譯、通過測試了。

參考:http://www.cppblog.com/tx7do/archive/2007/10/12/34014.aspx


2、 在以靜態庫方式使用zlib-1.2.6時,發現LNK2019報錯:

error LNK2019: 無法解析的外部符號 _deflateEnd error LNK2019: 無法解析的外部符號 _deflate error LNK2019: 無法解析的外部符號 _deflateInit_ error LNK2019: 無法解析的外部符號 _inflateEnd error LNK2019: 無法解析的外部符號 _inflate error LNK2019: 無法解析的外部符號 _inflateInit_
經查需要在使用時定義ZLIB_WINAPI宏:
#ifdef _WIN32 #define ZLIB_WINAPI #endif
#include "zlib.h" 參考: Zlib and LNK2019: unresolved external symbol

zlib編譯不過(Error A2070)解決方法(轉)