Alexey Loukianov
2006-Nov-03 07:48 UTC
[CentOS] -all-static problems when linking apps which require -lpthread and -lc
Hello all, I used to use fully statically linked PHP, which I build into RPM using own-written spec-file. I need to do this as there are a lot of boxes with old linuxes (RedHat 6.2, 7, 9) which I can't upgrade to CentOS3/4 right now for a several reasons I don't want to explain here. When I've been using CentOS 4.0 and 4.1 - there were no big problems to link PHP as static executable (i.e., when ldd says that "php not a dynamic executable"). All I have to do, is: LIBS="`pkg-config openssl --libs` `pkg-config --libs libxml-2.0` -lungif -lstdc++" \ LDFLAGS="-static -static-libgcc" \ CFLAGS="`pkg-config openssl --cflags` $RPM_OPT_FLAGS" \ ./configure ..... and LDFLAGS="-all-static -static-libgcc" \ CFLAGS="`pkg-config openssl --cflags` $RPM_OPT_FLAGS" \ make %{?_smp_mflags} It was sufficient to successfully compile totally static executable. After up2dating my compile box to CentOS 4.3 I receive following errors when trying to link PHP statically: ... ....(cuted a lot of lines and minor warnings).... .... /usr/lib/libpthread.a(lockfile.o)(.text+0x0): In function `flockfile': : multiple definition of `_IO_flockfile' /usr/lib/libc.a(flockfile.o)(.text+0x0): first defined here /usr/bin/ld: Warning: size of symbol `_IO_flockfile' changed from 30 in /usr/lib/libc.a(flockfile.o) to 18 in /usr/lib/libpthread.a(lockfile.o) /usr/lib/libpthread.a(lockfile.o)(.text+0x0): In function `flockfile': : multiple definition of `__flockfile' /usr/lib/libc.a(flockfile.o)(.text+0x0): first defined here /usr/bin/ld: Warning: size of symbol `__flockfile' changed from 30 in /usr/lib/libc.a(flockfile.o) to 18 in /usr/lib/libpthread.a(lockfile.o) /usr/lib/libpthread.a(lockfile.o)(.text+0x14): In function `funlockfile': : multiple definition of `_IO_funlockfile' /usr/lib/libc.a(funlockfile.o)(.text+0x0): first defined here /usr/bin/ld: Warning: size of symbol `_IO_funlockfile' changed from 30 in /usr/lib/libc.a(funlockfile.o) to 18 in /usr/lib/libpthread.a(lockfile.o) /usr/lib/libpthread.a(lockfile.o)(.text+0x14): In function `funlockfile': : multiple definition of `__funlockfile' /usr/lib/libc.a(funlockfile.o)(.text+0x0): first defined here /usr/bin/ld: Warning: size of symbol `__funlockfile' changed from 30 in /usr/lib/libc.a(funlockfile.o) to 18 in /usr/lib/libpthread.a(lockfile.o) /usr/lib/libkrb5.a(cc_file.o)(.text+0x1add): In function `krb5_fcc_generate_new': : warning: the use of `mktemp' is dangerous, better use `mkstemp' collect2: ld returned 1 exit status make: *** [sapi/cli/php] ?????? 1 As you can see, the trouble is that there are same functions defined in main glibc lib and in libpthread: [root at cappa SPECS]# nm /usr/lib/libc.a --defined-only 2>/dev/null | grep flockfile flockfile.o: 00000000 W flockfile 00000000 T __flockfile 00000000 T _IO_flockfile [root at cappa SPECS]# nm /usr/lib/libpthread.a --defined-only 2>/dev/null | grep flockfile 00000000 W flockfile 00000000 T __flockfile 0000003c T __flockfilelist 00000000 T _IO_flockfile So, the question is: what the hell?! Are there any ways to successfully compile PHP statically on CentOS4.3 box? And why the hell are this functions defined in both libc and libpthread, making impossible to link any programme statically when using both glibc and nptl? Of course, I can downgrade my compile-box to CentOS 4.1 or 4.0, but that wouldn't be cool as I'll loose any bug-fixes made to general libs in 4.2, 4.3 and following. So I dislike it . Thanks in advance. P.S. This is cross-post from: http://www.centos.org/modules/newbb/viewtopic.php?topic_id=5893&forum=28 -- Best regards, Alexey Loukianov mailto:aloukianov at lavtech.ru Software Development Department, Lavtech Corp http://mnogo.ru, http://lavtech.ru