You are not logged in.

#1 2022-03-09 22:41:59

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,534
Website

[SOLVED] makepkg.conf LDFLAGS --as-needed removing needed libs

I'm trying to package my 'nkk' library introduced here with sources available here.

While it builds fine locally, makepkg errors out with numerous undefined reference errors.  The problem is the default LDFLAGS setting from makepkg.conf including "--as-needed".  According to the man page for `ld` the behavior of this flag depends on it's order on the command line relative to libraries (e.g., specified with -l<libname>).

I confirmed that the linker command line run through makepkg fails when run manually, but moving the makepkg.conf-provided portion of the LDFLAGS to the end of the command line allows it to succeed.  Or in otherwords, using a command line with LDFLAGS after LDLIBS avoids this error.  While I know I could write my own makefile recipe to acheive this, I gather there is a reason that the standard / implicit makefile rules place LDFLAGS before LDLIBS.

Further, even if I were to hack around it for my build, any prospective users of the library would face the same problem - which highlights that I've clearly done something wrong in building this lib.  I am putting together a .pc file to distribute with this - but I don't know if that could be relevant as the only output from pkgconf with a .pc file for this lib would be the same CFLAGS and LDLIBS that are already included in the makefile.

Perhaps another way of asking this, is how can I get the linker to believe that the libraries specified are actually needed when my library is linked-to?

EDIT: I've narrowed this down a bit.  It seems the problem is in the compilation of the libary itself.  Running ldd on the .so file gives the following:

$ ldd libnkk.so.0 
	linux-vdso.so.1 (0x00007ffc58392000)
	libc.so.6 => /usr/lib/libc.so.6 (0x00007f39cfecc000)
	/usr/lib64/ld-linux-x86-64.so.2 (0x00007f39d00f4000)

This is clearly incomplete as the library code calls pango, cairo, and libwayland functions.  I also confirmed that the ldd output for other libraries (e.g., librcairo.so) include all the libs they depend on.  So this appears to be the cause - though it doesn't get me closer to the solution.

EDIT: *major head-desk* it turns out I wasn't using implicit or built in make rules for the linking of the final library as I wrote my own recipe to include the soname.  And in my recipe I didn't include LDFLAGS and LDLIBS.  Once they were added to the recipe all is better.  Now where's my PEBKAC award?

Last edited by Trilby (2022-03-10 22:57:37)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

Board footer

Powered by FluxBB