Search code examples
clinuxgccgnu-toolchain

Error building Glib due to undefined reference in libffi


I am currently working on building Glib version 2.45.8 on CentOS 7 running on x86-64 targeting a custom distro based off Linux from Scratch running on x86-64. There is a problem linking with libffi which is version 3.2.1.

path/to/build/directory/bin/ld: warning: libc.so.6, needed by //lib/../libffi.so, not found (try using -rpath or -rpath-link)
path/to/build/directory/lib64/libffi.so: undefined reference to `free@GLIBC_2.2.5'
path/to/build/directory/lib64/libffi.so: undefined reference to `mkostemp@GLIBC_2.7'
(etc ... there are about 15 undefined references total)
path/to/build/directory/lib64/libffi.so: undefined reference to `__getdelim@GLIBC_2.2.5'
path/to/build/directory/lib64/libffi.so: undefined reference to `getenv@GLIBC_2.2.5'

Using -rpath or -rpath-link will not work because the libc.so.6 file does not exist anywhere in the file system for my build.

However I do have libc.so and libc.so.0 in path/to/build/directory/lib64/ the directory in which libc.so.6 cannot be found.

Here are my ./configure and make commmands.

glib_cv_stack_grows=no \
glib_cv_uscore=no \
ac_cv_func_posix_getpwuid_r=yes \
ac_cv_func_posix_getgrgid_r=yes \
LIBFFI_CFLAGS=-lffi \
LIBFFI_LIBS=-lffi \
ZLIB_CFLAGS=-lz \
ZLIB_LIBS=-lz \
PKG_CONFIG_LIBDIR=$TARG/lib/pkgconfig \
./configure --prefix=/ --host=x86_64-linux --with-libiconv

make -j32 LDFLAGS=-liconv

How do I get the correct libc.so to be built?


Solution

  • There we several things that had to be done to solve this problem. The first thing I found out was that if software has a dependancy on libc.so.6 it was built against glibc. However our toolchain for this build is using uClibc instead, which does not produce libc.so.6 when it is built. The solution was to write the LIBFFI and ZLIB clags and libs to link to the libffi and zlib built with uClibc.

    glib_cv_stack_grows=no \
    glib_cv_uscore=no \
    ac_cv_func_posix_getpwuid_r=yes \
    ac_cv_func_posix_getgrgid_r=yes \
    ZLIB_CFLAGS=-I$TARG/include \
    ZLIB_LIBS="-L$TARG/lib -lz" \
    LIBFFI_CFLAGS=-I$TARG/include \
    LIBFFI_LIBS="$TARG/lib/libffi.a" \
    PKG_CONFIG_LIBDIR=$TARG/lib/pkgconfig \
    ./configure --prefix=/ --host=x86_64-linux --with-libiconv
    
    make -j32 LDFLAGS=-liconv