Comment 60 for bug 336634

Revision history for this message
In , Nicolas (nicolas-redhat-bugs) wrote :

(In reply to comment #26)
...
> I'm writing a cairo app, so I want to link it to libcairo. However, in order to
> compile my app, it also needs to be get the Xrender headers and link to
> libXrender. Now, I could directly link my app to libXrender, but since I don't
> use any Xrender symbols, it's extra baggage. The linker will still resolve all
> the symbols at build time because libXrender is marked with a a DT_NEEDED tag
> in libcairo.
I Don't use cairo, so forgive me if I say weird things.
If you really do not use libXrender symbol while using cairo, why just not include cairo-xlib-xrender.h which is the only one to declare X11/extensions/Xrender.h. In the majority of the cases, cairo.pc should have Requires: xrender >= 0.6 IMO.
Now if linking with xrender is only optional when using cairo, then it should be handled in another .pc or if cairo apps aren't expecting to directly links xrender at all, then it should be best to have X11/extensions/Xrender.h not included at all from the cairo-devel (so it will not be exposed from the cairo API).

> $ readelf -d /usr/lib/libcairo.so | grep NEEDED
The internal dependency of cairo itself is not in question.
...
> So, there's no runtime lookup of undefined symbols, I just want link my app
As you have defined your fictional app not to use symbol from xrender, it is necessary true. But doesn't help with some more info either.

> with "gcc -lcairo -o myapp myapp.c" instead of "gcc -lcairo -lXrender -lX11
> ...". On the other hand, static linking myapp would require that I pull in all
> the libraries to resolve all symbols.
What if an application (compiled gcc -lcairo -o myapp myapp.c ) using cairo and xrender symbol is provided on a system where cario have been compiled without xrender and the xrender library isn't available ?

> Regardless of how I want to link cairo, I need to be able to find the headers
> for fontconfig, Xrender and X11 since the datatypes are exposed by cairo.
So why they aren't in Requires: instead of Requires.private ?
OK , there is the Overlink problem , so another workaround would be to have @LIBX11_CFLAGS@ @LIBX11_CFLAGS@ @LIBX11_CFLAGS@ added in cairo.pc.in at the Clags libs.Then the cairo maintainer would have to requires the related -devel package manually.

But in the majority of the cases, Cflags and Libs from Requires.private doesn't matches. When building your application against cario shared/static, you don't need the -I/usr/include/libpng12 for example. while you will need the -lpng while your binary will be linked statically.
This is usually the case since whenever it is possible, internal dependencies should be hidden from the API.

> That's the extremely common case where one library uses another library's
> datatypes and symbols. It does have something to do with static linking, but
> it's all part of not acquiring more DT_NEEDED libs then necessary.
A agree that there is a need to reduce linking whenever it is possible.
> http://wiki.mandriva.com/en/Overlinking

> As I said before, the case you're describing with gconf and dbus is different
> and is not handled really well by pkg-config since it expects that you will
> need to access the dbus headers when compiling. Maybe there should be another
> pkg-config field like Requires.privatelib that does not expose the CFLAGS.
To sum up, Requires.private seems to be used when:
- compiling staticaly for the libs
- compiling shared/static for the include pathes.
This sound like a miss design for me.