-
Notifications
You must be signed in to change notification settings - Fork 23
Description
This issue is with respect to master 9473b6e
It is not about the v0.39.0.
I believe that there is an error in configure.ac, but my understanding of autoconf is limited.
Behavior
In what follows, assume that /opt/homebrew/lib/libz.a exists and the /opt/homebrew/include contains the appropriate header files.
Expected behavior
Here is what one would expect in two different cases.
-
If I do not specify a static libz location as either a shell variable or with the configure command, configure should look for the dynamic libz library instead of the a static one. (Note that on vanilla macOS the dynamic library exists, but not the static one.)
-
If I do say something like
configure --with-static-libz=/opt/homebrewthe script should look for/opt/homebrew/lib/libz.a
Actual behavior
No matter what I specify as an argument to --with-static-libz`, configure acts as if I have given an empty string, yielding this error:
configure: error: Could not find libz.a library for static linking in: "/lib"
That violates expectation 2.
Expectation 1 is also violated because even if I don't use --with-static-libz at all, I get the same error.
kThat is, both
./configure
and
./configure --with-static-libz=/opt/homebrew
insist on lookin looking for /lib/libz.a
Workaround
WITH_STATIC_LIBZ=/opt/homebrew ./configure
works, although it does require that I have installed a static libz.a instead of just using the the dynamic library that comes with the operating system.
Analysis of possible cause
I believe the problem with with line 74 of configure.ac
with_static_libz="$WITH_STATIC_LIBZ"
which is somehow conflicting with the AC_ARG_WITH processing that follows. I have not looked at autoconf's AC_ARG_WITH definition or documentation, but somehow $with_static_libz is the empty
Furthermore, that line is not checking whether the environment variable exists and isn't empty. So when the user has never set WITH_STATIC_LIBZ, with_static_libz ends up equal to "". And so the test a few lines later of [test -f "$with_static_libz/lib/libz.a" will look for /lib/libz.a.
Here is some more of the relevant code,
with_static_libz="$WITH_STATIC_LIBZ"
AC_ARG_WITH([static-libz],
[AS_HELP_STRING([--with-static-libz=<path>],
[Prefix to static install of libz. Directory that has lib and include within it.])],
[AS_IF([test -f "$with_static_libz/lib/libz.a"],
[AC_MSG_NOTICE([Static linking to libz.a located in "$with_static_libz/lib"])],
[AC_MSG_ERROR([Could not find libz.a library for static linking in: "$with_static_libz/lib"])])]
)
A note for macOS users for the workaround
The reason that this problem shows up on macOS is because expectation 1 is failing. With that, configure should find and use the /usr/lib/ibz.VERSION.dylib dynamic library and not even try to find the static library.
It is possible to use home brew to install zlib with brew install zlib , but homebrew is reluctant to add the installed bits in /opt/homebrew/lib because it (correctly) doesn't want to set things up that might conflict with zlib that comes with macOS.
I, probably unwisely, simply forced brew to do what it was warning me not to do with
brew link --force zlib
But I could have just manually copied things to a temporary directory created only for building this (because it is going to use a static library) with a structure like
my-static-zlib-place
|── include
│ ├── zconf.h
│ └── zlib.h
└── lib
└── libz.a
and then set WITH_STATIC_LIBZ to be path to my-static-zlib-place