Skip to content

Conversation

@zero-rp
Copy link

@zero-rp zero-rp commented Nov 23, 2025

#1086

Dynamic libraries can only be searched if they have been generated.

…ated.

Dynamic libraries can only be searched if they have been generated.
@Neustradamus
Copy link

@madler: Have you seen this PR?

@Vollstrecker
Copy link
Contributor

Nope, they can be searched always. minizip is now part of zlib, but if this is changed for any reason in the future there shouldn't be any traces of zlib in there.

This breaks more than it fixes as ZLIB::ZLIB does not exist if ZLIB_BUILD_SHARED is not set so in as with the self-contained variant it is possible that other projects include just minizip and use some other zlib (maybe system searched earlier, maybe some patched version from another subdir). If they decide to use systems zlib and it's the first usage, the search never happens and the configure will fail.

@zero-rp
Copy link
Author

zero-rp commented Nov 24, 2025

For example, my current project directly includes the zlib code directory and only uses the static library and minizip static library, causing compilation to fail directly. My configuration is as follows:
set(ZLIB_BUILD_TESTING OFF CACHE BOOL "" FORCE)
set(ZLIB_BUILD_SHARED OFF CACHE BOOL "" FORCE)
set(ZLIB_BUILD_STATIC ON CACHE BOOL "" FORCE)
set(ZLIB_BUILD_MINIZIP ON CACHE BOOL "" FORCE)
set(MINIZIP_BUILD_SHARED OFF CACHE BOOL "" FORCE)
set(MINIZIP_BUILD_TESTING OFF CACHE BOOL "" FORCE)
set(MINIZIP_ENABLE_BZIP2 OFF CACHE BOOL "" FORCE)
set(MINIZIP_INSTALL OFF CACHE BOOL "" FORCE)
ADD_SUBDIRECTORY(zlib)

@zero-rp
Copy link
Author

zero-rp commented Nov 24, 2025

Or should I modify it to check the MINIZIP_BUILD_SHARED condition?

@Vollstrecker
Copy link
Contributor

k, that's a valid reason and fix. Searching the shared if needed. Have you checked what happens if only static is requested?

I think the build breaks as no (interpreted as all) components are specified. I wanted to change that to only search for what's really needed (actually wanted this already 2 weeks ago). Would you mind to wait another 1 or 2 days to refine that?

@zero-rp
Copy link
Author

zero-rp commented Nov 24, 2025

My project uses a root CMake instance to compile all third-party libraries in a single call. If dynamic libraries are used, the libraries need to be installed in the environment first. I need my project to include the zlib library code itself, without relying on external libraries.

@zero-rp
Copy link
Author

zero-rp commented Nov 24, 2025

For example, in the Android NDK environment, I only need to statically compile all the code into a single .so file once.

@zero-rp
Copy link
Author

zero-rp commented Nov 24, 2025

Simply put, my entire project is contained in the form of source files, and the corresponding binary files haven't been generated and installed yet when searching for libraries.

@zero-rp
Copy link
Author

zero-rp commented Nov 24, 2025

k, that's a valid reason and fix. Searching the shared if needed. Have you checked what happens if only static is requested?

I think the build breaks as no (interpreted as all) components are specified. I wanted to change that to only search for what's really needed (actually wanted this already 2 weeks ago). Would you mind to wait another 1 or 2 days to refine that?

With the current modifications, everything works correctly, and minizipstatic compiles successfully.

@zero-rp
Copy link
Author

zero-rp commented Nov 24, 2025

k, that's a valid reason and fix. Searching the shared if needed. Have you checked what happens if only static is requested?
I think the build breaks as no (interpreted as all) components are specified. I wanted to change that to only search for what's really needed (actually wanted this already 2 weeks ago). Would you mind to wait another 1 or 2 days to refine that?

With the current modifications, everything works correctly, and minizipstatic compiles successfully.

~/zlib/build# cmake -DZLIB_BUILD_MINIZIP=1 -DMINIZIP_ENABLE_BZIP2=0 ../
-- Looking for fopen64
-- Looking for fopen64 - not found
-- Configuring done (0.0s)
-- Generating done (0.0s)
-- Build files have been written to: /root/zlib/build

~/zlib/build# make all
[ 21%] Built target zlib
[ 43%] Built target zlibstatic
[ 45%] Built target zlib_example
[ 48%] Built target minigzip
[ 51%] Built target zlib_example64
[ 54%] Built target zlib_static_example
[ 56%] Built target static_minigzip
[ 59%] Built target infcover
[ 62%] Built target zlib_static_example64
[ 63%] Building C object contrib/minizip/CMakeFiles/libminizip.dir/ioapi.c.o
[ 64%] Building C object contrib/minizip/CMakeFiles/libminizip.dir/mztools.c.o
[ 66%] Building C object contrib/minizip/CMakeFiles/libminizip.dir/unzip.c.o
[ 67%] Building C object contrib/minizip/CMakeFiles/libminizip.dir/zip.c.o
[ 68%] Linking C shared library libminizip.so
[ 68%] Built target libminizip
[ 70%] Building C object contrib/minizip/CMakeFiles/minizip.dir/ioapi.c.o
[ 71%] Building C object contrib/minizip/CMakeFiles/minizip.dir/minizip.c.o
[ 72%] Building C object contrib/minizip/CMakeFiles/minizip.dir/zip.c.o
[ 74%] Linking C executable minizip
[ 74%] Built target minizip
[ 75%] Building C object contrib/minizip/CMakeFiles/miniunzip.dir/ioapi.c.o
[ 77%] Building C object contrib/minizip/CMakeFiles/miniunzip.dir/miniunz.c.o
[ 78%] Building C object contrib/minizip/CMakeFiles/miniunzip.dir/unzip.c.o
[ 79%] Building C object contrib/minizip/CMakeFiles/miniunzip.dir/zip.c.o
[ 81%] Linking C executable miniunzip
[ 81%] Built target miniunzip
[ 82%] Building C object contrib/minizip/CMakeFiles/libminizipstatic.dir/ioapi.c.o
[ 83%] Building C object contrib/minizip/CMakeFiles/libminizipstatic.dir/mztools.c.o
[ 85%] Building C object contrib/minizip/CMakeFiles/libminizipstatic.dir/unzip.c.o
[ 86%] Building C object contrib/minizip/CMakeFiles/libminizipstatic.dir/zip.c.o
[ 87%] Linking C static library libminizip.a
[ 87%] Built target libminizipstatic
[ 89%] Building C object contrib/minizip/CMakeFiles/minizipstatic.dir/ioapi.c.o
[ 90%] Building C object contrib/minizip/CMakeFiles/minizipstatic.dir/minizip.c.o
[ 91%] Building C object contrib/minizip/CMakeFiles/minizipstatic.dir/zip.c.o
[ 93%] Linking C executable minizipstatic
[ 93%] Built target minizipstatic
[ 94%] Building C object contrib/minizip/CMakeFiles/miniunzipstatic.dir/ioapi.c.o
[ 95%] Building C object contrib/minizip/CMakeFiles/miniunzipstatic.dir/miniunz.c.o
[ 97%] Building C object contrib/minizip/CMakeFiles/miniunzipstatic.dir/unzip.c.o
[ 98%] Building C object contrib/minizip/CMakeFiles/miniunzipstatic.dir/zip.c.o
[100%] Linking C executable miniunzipstatic
[100%] Built target miniunzipstatic

@Vollstrecker
Copy link
Contributor

~/zlib/build# cmake -DZLIB_BUILD_MINIZIP=1 -DMINIZIP_ENABLE_BZIP2=0 ../

That should have worked before as this is what is run in the tests here.

You fixed:

~/zlib/build# cmake -DZLIB_BUILD_MINIZIP=1 -DMINIZIP_ENABLE_BZIP2=0 -DMINIZIP_BUILD_SHARED=0 ../

I was asking for:

~/zlib/build# cmake -DZLIB_BUILD_MINIZIP=1 -DMINIZIP_ENABLE_BZIP2=0 -DMINIZIP_BUILD_STATIC=0 ../

@zero-rp
Copy link
Author

zero-rp commented Nov 24, 2025

~/zlib/build# cmake -DZLIB_BUILD_MINIZIP=1 -DMINIZIP_ENABLE_BZIP2=0 ../

That should have worked before as this is what is run in the tests here.

You fixed:

~/zlib/build# cmake -DZLIB_BUILD_MINIZIP=1 -DMINIZIP_ENABLE_BZIP2=0 -DMINIZIP_BUILD_SHARED=0 ../

I was asking for:

~/zlib/build# cmake -DZLIB_BUILD_MINIZIP=1 -DMINIZIP_ENABLE_BZIP2=0 -DMINIZIP_BUILD_STATIC=0 ../

Yes, it's fixed. I was just testing whether my patch would affect shared library mode.This proves that everything is working correctly, whether in shared library mode or static library mode.

@Vollstrecker
Copy link
Contributor

Nice, we have a working solution. I still would like to refine that patch by using components for search and let each part just search for the parts it needs. First because I think it's cleaner and second just to have code that others can use to see how this all is supposed to work out in the project.

Unfortunately I found that the actions are broken atm and need to wait for #1116 to itegrate that cleanly.

@zero-rp
Copy link
Author

zero-rp commented Dec 9, 2025

Can this PR be used?

@madler
Copy link
Owner

madler commented Dec 9, 2025

Unfortunately I found that the actions are broken atm and need to wait for #1116 to itegrate that cleanly.

It has been applied and the actions seem to be working now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants