[build2] Naming of library imports from pkg-config files

Boris Kolpackov boris at codesynthesis.com
Tue Aug 1 09:05:55 UTC 2023


Christopher Head <build2 at chead.ca> writes:

> I’m still missing something though. Maybe I’m not understanding what
> you wrote correctly, but it seems like you’re saying that build2 first
> looks for a .so file based on the <target-name> part, then takes the
> directory in which it found that .so file, appends /pkgconfig, uses
> that as the .pc file search path, and looks for a .pc file in there
> named either <target-name>.pc or <project-name>.pc.

Yes, this is pretty much the semantics except that there is one nuance:
after not finding any .a/.so in each library search path we still checks
for the .pc file in the pkgconfig/ subdirectory in order to handle binless
libraries (the more general term we use for header-only libraries).


> But that doesn’t seem to agree with my experience. You gave zlib as an
> example where the .pc file doesn’t match the .so file, and that’s a
> great example as I’m actually using it in my current project. But not
> knowing what I was supposed to do, I’m importing it as “zlib%lib{zlib}”,
> and this works! Despite the fact that there is no “libzlib.so” anywhere.

I believe this "works" via that binless logic: zlib.pc is found as binless
and -lz it has in its Libs is treated as its binful prerequisite.


> Another example is libxml2: the .pc file is
> /usr/lib64/pkgconfig/libxml-2.0.pc, the .so file is
> /usr/lib64/libxml2.so, but I can even do “import libs =
> libxml-2.0%lib{wobble}” and it works.

Yes, the same story.


> It would be really nice to have the full logic written up in the build2
> manual somewhere.

While agree it would be helpful to document this somewhere, I am not
sure the manual is the right place. I mean, theoretically it is, but
if we document every C/C++ build nuance like this (of which there are
hundreds), it will be a thousand-page tome. It is currently already
200 pages and hardly anyone reads it because it's "too long".

Lately we've been capturing this sort of things in HOWTOs so maybe
we can do it there as a more broad "What target name should I use
to import an unpackaged, system-installed library" question?

https://github.com/build2/HOWTO/


> Once I understand what it is, I wouldn’t mind writing something up
> myself and submitting it as a PR, if that would be useful.

Yes, that would definitely be helpful, thanks!


> By the way, I’m using version 0.14.0 as that’s the latest packaged by
> Gentoo, so if this changed in the last couple of versions, that might
> be an explanation.

No, I don't believe there were any changes in this logic. But 0.14.0 is
quite an outdated version.



More information about the users mailing list