fix find zlib.so instead of zlib.a when NDK >= 19#19522
Merged
alalek merged 2 commits intoopencv:3.4from Feb 14, 2021
Merged
Conversation
On Android platform, `libopencv_imgcodecs.a` is built, expected to depend on `libz.so`. However, since Android NDK r19, NDK's `libz.a` is found instead of `libz.so`, leading to link error (not found libz.a) on machines without same NDK version & direcotry. Since Android NDK-r19, toolchain pieces are installed to `$NDK/toolchains/llvm/prebuilt/<host-tag>/...`, including `libz.so`. Also installed to old paths (`<NDK>/platforms` and `<NDK>/sysroot`) in NDK r19, r20, r21, but since NDK 22, old paths are removed. - https://github.com/android/ndk/wiki/Changelog-r19 - https://github.com/android/ndk/wiki/Changelog-r22 With this commit, `libz.so` can be correctly found in NDK<19 and NDK>=19. `ZLIB_LIBRARIES` is also simplified as `z`, by appending match (regex) patterns for new toolchain installation directory's libz.so's paths.
Contributor
Author
|
Note: this commit tested locally, with cmake 3.19.4, without modification of |
Contributor
Author
|
Note: this PR should only affect android platform. Android arm64 platform may fail, #19521 fix that failure and should be merged first. |
4 tasks
alalek
reviewed
Feb 13, 2021
cmake/OpenCVFindLibsGrfmt.cmake
Outdated
| if(ZLIB_LIBRARIES MATCHES "/usr/(lib|lib32|lib64)/libz.so$") | ||
| if(ZLIB_LIBRARIES MATCHES "/usr/(lib|lib32|lib64)/libz.so$" | ||
| OR ZLIB_LIBRARIES MATCHES "/usr/lib/(aarch64-linux-android|x86_64-linux-android)/(2[1-9]|3[0-9])/libz.so" | ||
| OR ZLIB_LIBRARIES MATCHES "/usr/lib/(arm-linux-androideabi|i686-linux-android)/(1[6-9]|(2|3)[0-9])/libz.so" |
Member
There was a problem hiding this comment.
I believe we can use here generic pattern here:
"/usr/lib.*/libz.so$"
and add two control variables:
if((OPENCV_FORCE_ANDROID_ZLIB_Z
OR ZLIB_LIBRARIES MATCHES "/usr/lib.*/libz.so")
AND NOT OPENCV_SKIP_ANDROID_ZLIB_Z
)
set(ZLIB_LIBRARIES z)
endif()
(checked locally with NDK 18, 20, 21)
Contributor
Author
There was a problem hiding this comment.
The mentioned generic pattern is simple. It's OK to use that.
For the mentioned two control variables, on android platform:
- I think there are only two origins for zlib: build from source(libz.a), or use NDK diretories(libz.so), thus :
OPENCV_FORCE_ANDROID_ZLIB_Z: is same asNOT BUILD_ZLIBOPENCV_SKIP_ANDROID_ZLIB_Z: is same asBUILD_ZLIB
So I would like to use:
if(ZLIB_LIBRARIES MATCHES "/usr/lib.*/libz.so$")
set(ZLIB_LIBRARIES z)
endif()
alalek
approved these changes
Feb 14, 2021
Merged
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Android platform,
libopencv_imgcodecs.ais built, expected todepend on
libz.so. However, since Android NDK r19, NDK'slibz.ais found instead of
libz.so, leading to link error(not found libz.a) on machines without same NDK version & direcotry.
Since Android NDK-r19, toolchain pieces are installed to
$NDK/toolchains/llvm/prebuilt/<host-tag>/..., includinglibz.so.Also installed to old paths (
<NDK>/platformsand<NDK>/sysroot)in NDK r19, r20, r21, but since NDK 22, old paths are removed.
With this commit,
libz.socan be correctly found in NDK<19 and NDK>=19.ZLIB_LIBRARIESis also simplified asz, by appending match (regex)patterns for new toolchain installation directory's libz.so's paths.
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.