From matthias.andree at gmx.de Wed Jul 16 14:03:49 2025 From: matthias.andree at gmx.de (Matthias Andree) Date: Wed, 16 Jul 2025 14:03:49 +0200 Subject: Bug: several databases' pkg-config .pc files lack -lpthread In-Reply-To: References: <59cc3c27-86ba-47a0-8a32-09ea0b6ed8b7@gmx.de> Message-ID: [I had a prior discussion on OpenBSD's ports@ mailing list, now copying to bogofilter's dev@ mailing list, too.] Am 14.07.25 um 12:59 schrieb Stuart Henderson: > On 2025/07/14 10:40, Matthias Andree wrote: >> It is conventional for OpenBSD to open bug reports for ports through >> sendbug(1) or via bugs@? I skimmed a bit through the ports FAQ and >> "Reporting problems" and a few messages randomly picked from the June and >> July 2025 ports mailing list archives, and it doesn't look so. > email to ports@ and/or the person listed as maintainer of the relevant port. > >> The issue is that at least these two ports guys >> >> - databases/lmdb >> - databases/sqlite3 >> >> link against pthread these days, but their pkg-config file does not list >> -lpthread when queried via pkgconfig --libs . > I'd expect > >> Consequence: bogofilter itself is single-threaded and does not use >> material from the POSIX threads library itself, so won't add -pthreads, >> -lpthreads or similar. It does use the respective pkg-config file of lmdb >> or sqlite3 for --libs and --cflags, and then fails to link any of the >> database-related programs constituting bogofilter, because neither >> >> pkg-config --libs lmdb >> >> nor >> >> pkg-config --libs sqlite3 >> >> gives me -lpthreads on the output. Excerpt from linker error: >> >>> ld: error: undefined symbol: pthread_mutexattr_init >>>>>> referenced by sqlite3.c:29857 >>>>>> sqlite3.o:(pthreadMutexAlloc) in archive /usr/local/lib/libsqlite3.a >>> $ pkg-config --libs sqlite3 >>> -L/usr/local/lib -lsqlite3 >> What I find confusing about this is that there was some effort to fix that >> for sqlite3 - and I haven't built the sqlite3 from source but just used >> "pkg_add sqlite3" on my OpenBSD 7.7 VM. (Which itself got updated through >> several releases by way of sysupgrade followed by syspatch and pkg_add >> -u): >> >> https://cvsweb.openbsd.org/cgi-bin/cvsweb/ports/databases/sqlite3/Makefile#rev1.134 > That was "libs.private" as used for static linking. I wouldn't normally > expect pthread to be listed in "libs" if the .so has a NEEDED pointing > at libpthread as ld.so would normally resolve that itself at runtime. > >> But lmdb's .pc file definitely doesn't match that LMDB links against >> pthreads these days: >> >> https://cvsweb.openbsd.org/cgi-bin/cvsweb/ports/databases/lmdb/files/lmdb.pc.in?rev=1.1&content-type=text/x-cvsweb-markup > I think pkgconfig --libs would normally just be expected to list the > linker options needed when linking against the shared library. > >> Excerpt from linker error: >>> ld: error: undefined symbol: pthread_mutexattr_init >>> referenced by sqlite3.c:29857 >>> sqlite3.o:(pthreadMutexAlloc) in archive /usr/local/lib/libsqlite3.a > Here you're linking the static library, so you need to tell pkg-config > that's what you're doing: > > $ pkg-config --libs sqlite3 > -L/usr/local/lib -lsqlite3 > > $ pkg-config --static --libs sqlite3 > -L/usr/local/lib -lsqlite3 -lz -lm -lpthread > > I don't think there's a problem with the sqlite port, but it looks like > -lpthread is indeed missing from lmdb's libs.private. So, for posterity I'll document what the bug was and how to solve it. The package in question (bogofilter) uses GNU autoconf and automake, and a few macros from other packages (below). 1. I wasn't using pkg-config properly, so I didn't read in the variables properly. I added PKG_PROG_PKG_CONFIG early enough in configure.ac because the PKG_CHECK_* macros were in a conditional case ... esac statement because they check the --with-database=WHATEVER configure argument (AC_ARG_WITH), else pkg-config would be skipped. 2a. I also wasn't using AC_LIB_LINKFLAGS properly. While I called the macro properly, I didn't Do The Right Thing with the output. The shared library argument go into LTLIBwhatever (mind the LTLIB prefiy), and LIBwhatever contains the arguments for a static link. So LTLIBwhatever has to go in the Makefile.am's *LDADD, not LIBwhatever. 2b. AC_LIB_LINKFLAGS has optional arguments, and pthread can be listed as a dependency for lmdb as 2nd argument as a workaround. Extra autoconf/automake macros from other packages that bogofilter uses: + pkg.m4 (for PKG_* macros; OpenBSD packages that in metaconf, other systems may bundle it with package that has "pkgconf" or "pkg-config" in its name. I've seen too many.) + iconv.m4 (for AM_ICONV, usually packaged in a gettext-tools package) Regards, Matthias