This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: Gcc 5.4 Compilation failure with -fPIC: undefined reference to `getrpcbynumber'
- From: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- To: libc-help at sourceware dot org
- Date: Thu, 21 Jul 2016 17:17:57 -0300
- Subject: Re: Gcc 5.4 Compilation failure with -fPIC: undefined reference to `getrpcbynumber'
- Authentication-results: sourceware.org; auth=none
- References: <CADHp1NyCc4uSkFJ5E5Z9yTOwLv0hwaYGUMjM3DkWMko_H9tDrA@mail.gmail.com>
On 21/07/2016 15:40, Matt wrote:
> Hi,
>
> I've been trying various branches (master branch, 2.23 tag) and
> various configurations in order to compile libc on ubuntu 16.04 with
> gcc-5.real (Ubuntu 5.4.0-6ubuntu1~16.04.1) 5.4.0 20160609 with -fPIC
> (I want to create a shared library statically linking some glibc
> functions.
I thinking you are missing the point here: glibc already provides
both the shared and library and static library for static case. Also
static linking a shared library with a libc.a is problematic in a sense
libc maintains some internal states that might be interfered with the
libc shared library.
Why exactly do you need the libc functions on the shared library? Why
can't you just statically link libc against the program itself?
>
> I came up with this command:
> $ CFLAGS=" -fPIC -O2 -fno-stack-protector -U_FORTIFY_SOURCE "
> LD_LIBRARY_PATH="" ../configure --prefix=/home/teto/libcinstall
> --disable-shared --enable-static-nss --enable-obsolete-rpc
> --disable-werror
>
> but I keep ending up with:
> ===
> make[2]: Entering directory '/home/teto/glibc/nss'
> gcc -nostdlib -nostartfiles -static -o /home/teto/glibc/d/nss/getent
> /home/teto/glibc/d/csu/crt1.o /home/teto/glibc/d/csu/crti.o `gcc
> --print-file-name=crtbeginT.o` /home/teto/glibc/d/nss/getent.o
> -Wl,--start-group /home/teto/glibc/d/libc.a -lgcc -lgcc_eh
> -Wl,--end-group `gcc --print-file-name=crtend.o`
> /home/teto/glibc/d/csu/crtn.o
> /home/teto/glibc/d/nss/getent.o: In function `rpc_keys':
> getent.c:(.text+0xc37): undefined reference to `getrpcbynumber'
> getent.c:(.text+0xc64): undefined reference to `getrpcbyname'
> getent.c:(.text+0xc93): undefined reference to `setrpcent'
> getent.c:(.text+0xca9): undefined reference to `getrpcent'
> getent.c:(.text+0xcb3): undefined reference to `endrpcent'
> collect2: error: ld returned 1 exit status
> ../Rules:147: recipe for target '/home/teto/glibc/d/nss/getent' failed
> make[2]: *** [/home/teto/glibc/d/nss/getent] Error 1
> ====
> is there anything I can do to fix this ?
> also if I don't compile first with a simpler command, "libc-modules.h"
> doesn't get created, thus stopping the compilation process :/
>
> Best regards
>