pkgconf / pkgconf

package compiler and linker metadata toolkit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Non-library dependency

ppisar opened this issue · comments

I have a case where a library's public header includes a header from a different project so that application including the public header transitively includes the different project's header. But there is no need for the application to link to the different project's library.

My problem is that adding the other project to Requires of the library starts linking the application against the different project.

Concrete example is rpm-software-management/librepo#305:

zck.pc contains "Libs: -lzck"
librepo.pc contains "Libs: glib-2.0"
librepo's /usr/include/librepo/downloadtarget.h includes "<zck.h>".

A librepo's user rightfully claims the compiling his application fails because including <librepo/downloadtarget.h> fails on missing zck.h.

If I change librepo.pc to "Libs: glib-2.0 zck", it will fix the user's problem. But "pkg-config --libs librepo" will produce "-lzck" (in addition to glib-2.0 link flags) because pkg-config thinks that every dependency is a library dependency. In this case it's not true, the application does not need linking to zck. The new librepo.pc would cause overlinking.

I can image these solutions:

  1. zchunk project to deliver zck-headers.pc without "Libs:" in addition to zck.pc and librepo.pc to "Requires: zck-headers". This does not need changes in pkgconf, but it's not a generic solution. Similar problem can have any other project. I don't think projects should start deliver multiple pkg-config files just because somebody mights have this use case.
  2. pkgconf to introduce a new non-library dependency which would suppress extending "pkg-config --libs". E.g. "Requires.headers: zck" in librepo.pc would add zck as a dependency of librepo and addedd zck's include path to "pkg-config --cflags librepo" output, but it wouldn't add "-lzck" to "pkg-config --libs librepo".
  3. Do not change pkgconfig, neither zchunk. Add zck to librepo.pc Requires and claim that overlinking is a lesser problem then failing compilation.
  4. Do not change anything and reject the user's request with a claim that pkg-config is about for tracking libraries, not headers and user needs the declare the dependency in other means than with pkg-config file.

What's your opinion?

You should simply add the dependency to Requires.private. Other than one would expect, both pkg-config and pkgconf pull cflags from Requires.private even when not asking for --static. It has a test here:

libs_cflags_body()
{
export PKG_CONFIG_PATH="${selfdir}/lib1"
atf_check \
-o inline:"-fPIC -I/test/include/foo -L/test/lib -lbaz\n" \
pkgconf --libs --cflags baz
}

AFAIU the behavior exists just for your use case. And now even for you, it seems to break the principle of least surprise... See also #300

Amazing. I missed these details in pc(5) manual.