|
From: | M S |
Subject: | Re: Building shared library for lzlib |
Date: | Fri, 18 Oct 2024 18:53:08 +0000 |
Hi,
Thanks for the reply. I should have included the output of the make without the change, it is unable to build the unmodified distribution, as you can see here:
Actually I found another couple of issues when going back and getting the output, which I missed, but it doesn’t seem to affect the install.
(base) [unixwzrd@xanax: lzlib-1.14]$ make -v
GNU Make 4.4.1
Built for aarch64-apple-darwin24.0.0
Copyright (C) 1988-2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
(base) [unixwzrd@xanax: lzlib-1.14]$ ./configure --enable-shared
creating config.status
creating Makefile
VPATH = .
prefix = /usr/local
exec_prefix = $(prefix)
bindir = $(exec_prefix)/bin
datarootdir = $(prefix)/share
includedir = $(prefix)/include
infodir = $(datarootdir)/info
libdir = $(exec_prefix)/lib
mandir = $(datarootdir)/man
CC = gcc
AR = ar
CPPFLAGS =
CFLAGS = -Wall -W -O2
LDFLAGS =
ARFLAGS = -rcs
MAKEINFO = makeinfo
OK. Now you can run make.
(base) [unixwzrd@xanax: lzlib-1.14]$ make
gcc -Wall -W -O2 -c -o carg_parser.o carg_parser.c
gcc -Wall -W -O2 -DPROGVERSION=\"1.14\" -c -o minilzip.o minilzip.c
gcc -Wall -W -O2 -c -o lzlib.o lzlib.c
ar -rcs liblz.a lzlib.o
gcc -Wall -W -O2 -o minilzip carg_parser.o minilzip.o liblz.a
gcc -Wall -W -O2 -fpic -fPIC -c -o lzlib_sh.o lzlib.c
gcc -Wall -W -O2 -fpic -fPIC -shared -Wl,--soname=liblz.so.1 -o liblz.so.1.14 lzlib_sh.o
ld: unknown options: --soname=liblz.so.1
collect2: error: ld returned 1 exit status
make: *** [Makefile:61: liblz.so.1.14] Error 1
This fails because the linker is looking for the library, “—soname=liblz.so.1” which does not exist. Also this linker argument is to link with that library.
Here it is with the —soname removed, but the soversion in the Makefile is set to 1, and that can’t be found either. The linker cannot find "libel.so.1"
(base) [unixwzrd@xanax: lzlib-1.14]$ make
gcc -Wall -W -O2 -c -o carg_parser.o carg_parser.c
gcc -Wall -W -O2 -DPROGVERSION=\"1.14\" -c -o minilzip.o minilzip.c
gcc -Wall -W -O2 -c -o lzlib.o lzlib.c
ar -rcs liblz.a lzlib.o
gcc -Wall -W -O2 -o minilzip carg_parser.o minilzip.o liblz.a
gcc -Wall -W -O2 -fpic -fPIC -c -o lzlib_sh.o lzlib.c
gcc -Wall -W -O2 -fpic -fPIC -shared -Wl,liblz.so.1 -o liblz.so.1.14 lzlib_sh.o
ld: file cannot be open()ed, errno=2 path=liblz.so.1 in 'liblz.so.1'
collect2: error: ld returned 1 exit status
make: *** [Makefile:61: liblz.so.1.14] Error 1
Here is the output with my patch, the linker doesn’t need a stared object to link with to create the shared object. I also found a few other things which were inconsistent when looking deeper t reproducing the issue. Seems there was a lot of issues and
confusion over pkgversion and soversion, also the dependency Here’s the clean compile:
(base) [unixwzrd@xanax: lzlib-1.14]$ make -v
GNU Make 4.4.1
Built for aarch64-apple-darwin24.0.0
Copyright (C) 1988-2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
(base) [unixwzrd@xanax: lzlib-1.14]$ ./configure --enable-shared
creating config.status
creating Makefile
VPATH = .
prefix = /usr/local
exec_prefix = $(prefix)
bindir = $(exec_prefix)/bin
datarootdir = $(prefix)/share
includedir = $(prefix)/include
infodir = $(datarootdir)/info
libdir = $(exec_prefix)/lib
mandir = $(datarootdir)/man
CC = gcc
AR = ar
CPPFLAGS =
CFLAGS = -Wall -W -O2
LDFLAGS =
ARFLAGS = -rcs
MAKEINFO = makeinfo
OK. Now you can run make.
(base) [unixwzrd@xanax: lzlib-1.14]$ make
gcc -Wall -W -O2 -c -o carg_parser.o carg_parser.c
gcc -Wall -W -O2 -DPROGVERSION=\"1.14\" -c -o minilzip.o minilzip.c
gcc -Wall -W -O2 -c -o lzlib.o lzlib.c
ar -rcs liblz.a lzlib.o
gcc -Wall -W -O2 -o minilzip carg_parser.o minilzip.o liblz.a
gcc -Wall -W -O2 -fpic -fPIC -shared -o liblz.so.1.14 lzlib.o
gcc -Wall -W -O2 -o minilzip_shared carg_parser.o minilzip.o liblz.so.1.14
(base) [unixwzrd@xanax: lzlib-1.14]$ diff Makefile.in Makefile.dist.in
28,29c28,29
< lib$(libname).so.$(soversion) : lzlib.o
< $(CC) $(CFLAGS) $(LDFLAGS) -fpic -fPIC -shared -o $@ $<
---
> lib$(libname).so.$(pkgversion) : lzlib_sh.o
> $(CC) $(CFLAGS) $(LDFLAGS) -fpic -fPIC -shared -Wl,--soname=lib$(libname).so.$(soversion) -o $@ $<
34,35c34,35
< $(progname)_shared : $(objs) lib$(libname).so.$(soversion)
< $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(objs) lib$(libname).so.$(soversion)
---
> $(progname)_shared : $(objs) lib$(libname).so.$(pkgversion)
> $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(objs) lib$(libname).so.$(pkgversion)
47a48,50
>
> lzlib_sh.o : lzlib.c
> $(CC) $(CPPFLAGS) $(CFLAGS) -fpic -fPIC -c -o $@ $<
(base) [unixwzrd@xanax: lzlib-1.14]$ diff configure configure.dist
10,11c10
< # soversion=1.14
< soversion=${pkgversion}
---
> soversion=1
The -Wl, will instruct the linker to link with that library, you really don’t want the library to try to link with itself, and it won’t work anyway, you will get duplicate symbol errors IIRC, if someone has LD_LIBRARY_PATH, LD_FLAGS, or CFLAGS containing
a
-L/usr/local/lib
in them. I encountered this issue when trying to compile and link a new version of libiconv with the new macOS Sequoia libraries, I believe it was which kept insisting it link with itself in /usr/local/lib. In any event, the lines in your makefile,
lib$(libname).so.$(soversion) : lzlib.o
$(CC) $(CFLAGS) $(LDFLAGS) -fpic -fPIC -shared -o $@ $<
Will work correctly as shown in the compile above and should work on any other OS you try it on. $@ expands to the target lib$(libname).so.$(soversion) and $< will take the dependency, lzlib.o, which is what you want isn’t it?
I also removed the libel_sh.o because it is really unnecessary, once the libel.o file is built, it just needs the link step to either be made static or shared. This should also work on any flavor Linux/Unix system as well.
The mini_lzip also gets built too.
Cheers,
Mike
--- Michael Sullivan Distributed Thinking Systems LLC
unixwzrd@unixwzrd.ai LinkedIn: https://www.linkedin.com/in/unixwzrd/
GitHub: https://github.com/unixwzrd
Phone: +1-662-202-7716
|
[Prev in Thread] | Current Thread | [Next in Thread] |