From 84a290097bc5fcef4272567ad293fde614cff00b Mon Sep 17 00:00:00 2001 From: Zhuo Zhang Date: Fri, 12 Feb 2021 22:19:35 +0800 Subject: [PATCH] fix link order: put zlib after png/tiff/openexr Previous link dependency: imgcodecs --> zlib --> libpng this can generate imgcodecs shared lib, until Visual Studio integrated with vcpkg, which will additionally specify LIBPATH, pointing to vcpkg installed zlib (if any), which links the wrong zlib. Fixed link dependency: imgcodecs --> libpng --> zlib in this fixed case, symbols in zlib referenced in libpng will be found in the build-from-source static zlib, instead of the vcpkg one. related discussion: - https://github.com/microsoft/vcpkg/issues/16165 - https://github.com/opencv/opencv/issues/17051 - https://github.com/opencv/opencv/issues/10576 MSVC linking order reference pages: - https://docs.microsoft.com/en-us/cpp/build/reference/link-input-files?view=msvc-160 for link order - https://docs.microsoft.com/en-us/cpp/build/reference/linking?view=msvc-160 LIB environment variable, for library file searching - https://docs.microsoft.com/en-us/cpp/build/reference/libpath-additional-libpath?view=msvc-160 LIBPATH option, for library file searching --- modules/imgcodecs/CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/imgcodecs/CMakeLists.txt b/modules/imgcodecs/CMakeLists.txt index 92f380ea22..1b832eaa3a 100644 --- a/modules/imgcodecs/CMakeLists.txt +++ b/modules/imgcodecs/CMakeLists.txt @@ -13,11 +13,6 @@ if(HAVE_WINRT_CX AND NOT WINRT) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /ZW") endif() -if(HAVE_PNG OR HAVE_TIFF OR HAVE_OPENEXR) - ocv_include_directories(${ZLIB_INCLUDE_DIRS}) - list(APPEND GRFMT_LIBS ${ZLIB_LIBRARIES}) -endif() - if(HAVE_JPEG) ocv_include_directories(${JPEG_INCLUDE_DIR} ${${JPEG_LIBRARY}_BINARY_DIR}) list(APPEND GRFMT_LIBS ${JPEG_LIBRARIES}) @@ -58,6 +53,11 @@ if(HAVE_OPENEXR) list(APPEND GRFMT_LIBS ${OPENEXR_LIBRARIES}) endif() +if(HAVE_PNG OR HAVE_TIFF OR HAVE_OPENEXR) + ocv_include_directories(${ZLIB_INCLUDE_DIRS}) + list(APPEND GRFMT_LIBS ${ZLIB_LIBRARIES}) +endif() + if(HAVE_GDAL) include_directories(SYSTEM ${GDAL_INCLUDE_DIR}) list(APPEND GRFMT_LIBS ${GDAL_LIBRARY}) -- GitLab