Clogan/zlib_util.c:67: error: undefined reference to 'deflateInit2_'

美团点评的开源移动端基础日志库在win 7 android studio 3.0.1 ndk 16编译c时会出现一个错误如下 

09:34:48.492 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] D:\test\demos\Logan-Android\app\src\main\cpp\Clogan/zlib_util.c:67: error: undefined reference to 'deflateInit2_'

09:34:48.492 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] D:\test\demos\Logan-Android\app\src\main\cpp\Clogan/zlib_util.c:98: error: undefined reference to 'deflate'

09:34:48.493 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] D:\test\demos\Logan-Android\app\src\main\cpp\Clogan/zlib_util.c:100: error: undefined reference to 'deflateEnd'

09:34:48.493 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] D:\test\demos\Logan-Android\app\src\main\cpp\Clogan/zlib_util.c:179: error: undefined reference to 'deflateEnd'

09:34:48.493 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] D:\test\demos\Logan-Android\app\src\main\cpp\Clogan/zlib_util.c:208: error: undefined reference to 'deflateEnd'

09:34:48.493 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] clang.exe: error: linker command failed with exit code 1 (use -v to see invocation)

09:34:48.493 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] ninja: build stopped: subcommand failed.

这个我查了网上很多资料,都没有直接的答案,后来终于编译过去了,所以来分享一下,以免以后大家再入坑

解决方案:

在你出问题的那个CMakeLists.txt文件中添加如下代码:

link_libraries(z)

就一行代码就行了。

上面的代码错误提示说找不到相应的函数,其实这些找不到的函数都在一个zlib包里面,而这个包是ndk自带的,名字叫libz.so或者libz.a

 

 

你可能感兴趣的:(android开发)