Re: [PATCH]: Fix linking when ncurses is built with --with-termlib=tinfo

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tuesday 26 of June 2007, Karel Zak wrote:
> On Tue, Jun 19, 2007 at 08:58:04PM +0200, Arkadiusz Miskiewicz wrote:
> > When system ncurses is built with --with-termlib=tinfo option
> > then there are two libraries - libtinfo (which contains terminal
> > related functions) and libncurses (rest).
> >
> > Correctly link against libtinfo in such case.
>
> Why do you need extra -ltinfo? I see:

Because I use --as-needed linker option.

>
> # ldd /lib/libncurses.so.5
>       linux-gate.so.1 =>  (0xffffe000)
>       libc.so.6 => /lib/libc.so.6 (0xf7e5c000)
>       libdl.so.2 => /lib/libdl.so.2 (0xf7e57000)
>       libtinfo.so.5 => /lib/libtinfo.so.5 (0xf7e3f000)

libncurses doesn't provide tgetent function for example:

[arekm@tarm ~]$ objdump -T /usr/lib/libncurses.so.5|grep tgetent
[arekm@tarm ~]$ objdump -T /usr/lib/libtinfo.so|grep tgetent
0000deb3 g    DF .text  000005d9  Base        tgetent

Now if you use --as-needed then linker will throw away -lncurses since it 
doesn't provide needed tget* function and is simply not required. That's why 
you will get undefined reference.

Visual example :-)

[arekm@carme-pld ~]$ cat a.c
#include <curses.h>
#include <term.h>

int main() {
        tgetent("", "");
}

[arekm@carme-pld ~]$ gcc a.c -I/usr/include/ncurses -lncurses
[arekm@carme-pld ~]$ gcc a.c -I/usr/include/ncurses -ltinfo
[arekm@carme-pld ~]$ gcc a.c -I/usr/include/ncurses -Wl,--as-needed -lncurses
/home/users/arekm/tmp/cc6Uzb3p.o: In function `main':
a.c:(.text+0xf): undefined reference to `tgetent'
collect2: ld returned 1 exit status
[arekm@carme-pld ~]$ gcc a.c -I/usr/include/ncurses -Wl,--as-needed -ltinfo
[arekm@carme-pld ~]$    

> For example Fedora 7 uses tinfo, and the cal command is compiled
> without an extra -ltinfo:
>
> # ldd /usr/bin/cal
>        libncurses.so.5 => /lib64/libncurses.so.5 (0x0000003b66400000)
>        libc.so.6 => /lib64/libc.so.6 (0x0000003b51a00000)
>        libdl.so.2 => /lib64/libdl.so.2 (0x0000003b52200000)
>        libtinfo.so.5 => /lib64/libtinfo.so.5 (0x0000003b65800000)

So why do you need libncurses here?

[arekm@carme-pld ~]$ ldd /usr/bin/cal
        libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00002ae5205a3000)
        libc.so.6 => /lib64/libc.so.6 (0x00002ae5207e0000)
        /lib64/ld-linux-x86-64.so.2 (0x00002ae520387000)

>   Karel

-- 
Arkadiusz Miśkiewicz        PLD/Linux Team
arekm / maven.pl            http://ftp.pld-linux.org/
-
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux