我正在尝试使用CMake为Windows构建zlib 1.2.8,但是我遇到了构建错误,我不知道如何修复。 这是我的CMake GUI:
这会生成没有错误,但是当我构建生成的解决方案时。我收到这个错误:
2> ------ Build build:项目:zlib,配置:发布x64 ------
2 - ;创建库C:/Users/erik/Documents/zlib/1.2.8/project/zlib-1.2.8-vc10/Release/zlib.lib和对象C:/Users/erik/Documents/zlib/1.2.8/project /zlib-1.2.8-vc10/Release/zlib.exp
2 - ; inflate.obj:错误LNK2019:函数膨胀中引用的未解析的外部符号inflate_fast
2> infback.obj:错误LNK2001:未解析的外部符号inflate_fast
2> C:\ Users \ erik \ Documents \ zlib \ 1.2.8 \ project \ zlib-1.2.8-vc10 \ Release \ zlib.dll:致命错误LNK1120:1个未解析的外部
我不知道如何解决这个问题,所以我感谢任何帮助。
答案 0 :(得分:12)
根据https://wiki.apache.org/httpd/Win64Compilation,非常相似的错误意味着:
这意味着您在-DASMV -DASMINF或OBJ =" inffasx64.obj gvmat64.obj inffas8664.obj"中输入了拼写错误。因为inflate_fast是在inffas8664.c中定义的。
我能够通过简单的方式成功构建:
mkdir C:\Builds\zlib; cd C:\Builds\zlib
cmake -G "Visual Studio 12 2013" -A x64 D:\Downloads\zlib-1.2.8\
cmake --build .
我查看了我的cmake缓存,我发现AMD64设置为false,不像你的cmake-gui窗口显示的那样。将其设置为true会导致我出现各种构建错误,但不会显示您所显示的错误。
CMakeLists.txt表示此选项是启用AMD64程序集实现。没有这个似乎是最简单的解决方案。
答案 1 :(得分:9)
您需要在visual studio项目文件中包含 contrib \ masmx64 \ inffas8664.c 。
该文件包含inflate_fast
函数,该函数调用相应的asm
函数。
答案 2 :(得分:7)
日期: 20180804 ( 2018年8月4日 )
在使用汇编程序加速时,我发现此问题在(当前)最新版本: v1.2.11 ([GitHub]: madler/zlib - A massively spiffy yet delicately unobtrusive compression library (http://zlib.net))上是可重现的。 / p>
仅仅会发生此错误(显然, OS : Win ,构建工具链: VStudio 并启用了组件加速):
下面是减压过程中的“ 调用堆栈”( top-> down 等效于 outer-> inner )。
正常情况:
汇编器情况:
#2。 丢失(“ $ {ZLIB_SRC_DIR} /CMakeLists.txt” 对 inffast8664一无所知.c ),因此链条断裂,导致库无效。
通过添加以下内容使 CMakeLists.txt 知道该文件,
set(ZLIB_SRCS
${ZLIB_SRCS}
contrib/masmx64/inffas8664.c
)
在第〜#158 行(由if(MSVC)
和elseif (AMD64)
条件附加)。
也要发布全部更改。
zlib-1.2.11-msvc_x64_asm_speedups.diff :
--- CMakeLists.txt.orig 2017-01-15 08:29:40.000000000 +0200
+++ CMakeLists.txt 2018-09-03 13:41:00.314805100 +0300
@@ -79,10 +79,10 @@
endif()
set(ZLIB_PC ${CMAKE_CURRENT_BINARY_DIR}/zlib.pc)
-configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein
- ${ZLIB_PC} @ONLY)
-configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein
- ${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY)
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein
+ ${ZLIB_PC} @ONLY)
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein
+ ${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY)
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR})
@@ -136,30 +136,34 @@
set(ZLIB_ASMS contrib/amd64/amd64-match.S)
endif ()
- if(ZLIB_ASMS)
- add_definitions(-DASMV)
- set_source_files_properties(${ZLIB_ASMS} PROPERTIES LANGUAGE C COMPILE_FLAGS -DNO_UNDERLINE)
- endif()
+ if(ZLIB_ASMS)
+ add_definitions(-DASMV)
+ set_source_files_properties(${ZLIB_ASMS} PROPERTIES LANGUAGE C COMPILE_FLAGS -DNO_UNDERLINE)
+ endif()
endif()
if(MSVC)
if(ASM686)
- ENABLE_LANGUAGE(ASM_MASM)
+ ENABLE_LANGUAGE(ASM_MASM)
set(ZLIB_ASMS
- contrib/masmx86/inffas32.asm
- contrib/masmx86/match686.asm
- )
+ contrib/masmx86/inffas32.asm
+ contrib/masmx86/match686.asm
+ )
elseif (AMD64)
- ENABLE_LANGUAGE(ASM_MASM)
+ ENABLE_LANGUAGE(ASM_MASM)
set(ZLIB_ASMS
- contrib/masmx64/gvmat64.asm
- contrib/masmx64/inffasx64.asm
- )
+ contrib/masmx64/gvmat64.asm
+ contrib/masmx64/inffasx64.asm
+ )
+ set(ZLIB_SRCS
+ ${ZLIB_SRCS}
+ contrib/masmx64/inffas8664.c
+ )
endif()
- if(ZLIB_ASMS)
- add_definitions(-DASMV -DASMINF)
- endif()
+ if(ZLIB_ASMS)
+ add_definitions(-DASMV -DASMINF)
+ endif()
endif()
# parse the full version number from zlib.h and include in ZLIB_FULL_VERSION
上面是 diff 。有关如何在 Win 上应用补丁的信息,请参见[SO]: Run/Debug a Django application's UnitTests from the mouse right click context menu in PyCharm Community Edition? (@CristiFati's answer)(修补 utrunner 部分)(基本上,每行以开头)一个“ +” 符号进入,以一个“-” 符号开头的每一行都熄灭)。我正在使用 Cygwin , btw 。
我也将此补丁提交给了 [GitHub]: madler/zlib - Ms VisualStudio - Assembler speedups on x64 ,但我不确定它的命运如何,因为有超过 100 个请求待处理的请求。
输出:
e:\Work\Dev\StackOverflow\q029505121\build\x64>"c:\Install\Google\Android_SDK\cmake\3.6.4111459\bin\cmake.exe" -G "NMake Makefiles" -DAMD64=ON "e:\Work\Dev\StackOverflow\q029505121\src\zlib-1.2.11" -- The C compiler identification is MSVC 19.0.24215.1 -- Check for working C compiler: C:/Install/x86/Microsoft/Visual Studio Community/2015/VC/bin/amd64/cl.exe -- Check for working C compiler: C:/Install/x86/Microsoft/Visual Studio Community/2015/VC/bin/amd64/cl.exe -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Looking for sys/types.h -- Looking for sys/types.h - found -- Looking for stdint.h -- Looking for stdint.h - found -- Looking for stddef.h -- Looking for stddef.h - found -- Check size of off64_t -- Check size of off64_t - failed -- Looking for fseeko -- Looking for fseeko - not found -- Looking for unistd.h -- Looking for unistd.h - not found -- Renaming -- E:/Work/Dev/StackOverflow/q029505121/src/zlib-1.2.11/zconf.h -- to 'zconf.h.included' because this file is included with zlib -- but CMake generates it automatically in the build directory. -- The ASM_MASM compiler identification is MSVC -- Found assembler: C:/Install/x86/Microsoft/Visual Studio Community/2015/VC/bin/amd64/ml64.exe -- Configuring done -- Generating done -- Build files have been written to: E:/Work/Dev/StackOverflow/q029505121/build/x64 e:\Work\Dev\StackOverflow\q029505121\build\x64>"c:\Install\Google\Android_SDK\cmake\3.6.4111459\bin\cmake.exe" --build . --target zlibstatic Scanning dependencies of target zlibstatic [ 5%] Building C object CMakeFiles/zlibstatic.dir/adler32.obj adler32.c [ 10%] Building C object CMakeFiles/zlibstatic.dir/compress.obj compress.c [ 15%] Building C object CMakeFiles/zlibstatic.dir/crc32.obj crc32.c [ 21%] Building C object CMakeFiles/zlibstatic.dir/deflate.obj deflate.c Assembler code may have bugs -- use at your own risk [ 26%] Building C object CMakeFiles/zlibstatic.dir/gzclose.obj gzclose.c [ 31%] Building C object CMakeFiles/zlibstatic.dir/gzlib.obj gzlib.c [ 36%] Building C object CMakeFiles/zlibstatic.dir/gzread.obj gzread.c [ 42%] Building C object CMakeFiles/zlibstatic.dir/gzwrite.obj gzwrite.c [ 47%] Building C object CMakeFiles/zlibstatic.dir/inflate.obj inflate.c [ 52%] Building C object CMakeFiles/zlibstatic.dir/infback.obj infback.c [ 57%] Building C object CMakeFiles/zlibstatic.dir/inftrees.obj inftrees.c [ 63%] Building C object CMakeFiles/zlibstatic.dir/inffast.obj inffast.c Assembler code may have bugs -- use at your own risk [ 68%] Building C object CMakeFiles/zlibstatic.dir/trees.obj trees.c [ 73%] Building C object CMakeFiles/zlibstatic.dir/uncompr.obj uncompr.c [ 78%] Building C object CMakeFiles/zlibstatic.dir/zutil.obj zutil.c [ 84%] Building C object CMakeFiles/zlibstatic.dir/contrib/masmx64/inffas8664.obj inffas8664.c [ 89%] Building ASM_MASM object CMakeFiles/zlibstatic.dir/contrib/masmx64/gvmat64.obj Microsoft (R) Macro Assembler (x64) Version 14.00.24210.0 Copyright (C) Microsoft Corporation. All rights reserved. Assembling: E:\Work\Dev\StackOverflow\q029505121\src\zlib-1.2.11\contrib\masmx64\gvmat64.asm [ 94%] Building ASM_MASM object CMakeFiles/zlibstatic.dir/contrib/masmx64/inffasx64.obj Microsoft (R) Macro Assembler (x64) Version 14.00.24210.0 Copyright (C) Microsoft Corporation. All rights reserved. Assembling: E:\Work\Dev\StackOverflow\q029505121\src\zlib-1.2.11\contrib\masmx64\inffasx64.asm [100%] Linking C static library zlibstatic.lib [100%] Built target zlibstatic
注释:
@ EDIT0 :
@MarkAdler的评论([GitHub]: madler/zlib - ASM zlib build on Windows gives erroneous results)指出:
正在使用什么汇编代码? zlib的contrib目录中有一些。顺便说一句,contrib目录中的内容是zlib的 not 部分。它只是为了方便起见,并且得到了这些第三方贡献者的支持(或不支持)。我要做的就是从下一个发行版中删除有问题的代码。
编译警告也是如此(每个人都必须看过(很可能已被忽略)):
Assembler code may have bugs -- use at your own risk
显然,汇编程序的提速与 VStudio 的配合不太好。另外,在 x86 上存在几个问题:
[SO]: module unsafe for SAFESEH image C++ (@NayanaAdassuriya's answer)提出了一种解决方案(尽管它与问题没有直接关系)。简而言之, inffas32.asm 和 linker 的选项[MS.Docs]: /SAFESEH (Image has Safe Exception Handlers)不匹配。要摆脱它,可以:
由于我使用 cmake 为 cmdline 进行构建,因此我找到了解决方法。在 CMakeFiles 生成后(但在构建之前之前),我指定了它:
我敢肯定 cmake 提供了一种正确执行上述操作的方法,但我没有找到(也不进行彻底调查)。
一个令人讨厌的人是在解压缩过程中的 segfault (访问冲突)。为此,需要[GitHub]: madler/zlib - inffas32.asm struct/enum binding to zlib 1.2.9。
修复这些问题后,一切正常,并且性能改进与 x64 类似。