1

I am trying to build a Rust application for Yocto which uses a number of bindgen generated bindings to custom ioctl calls. My recipe includes the following dependency line:

DEPENDS += " clang ncurses ncurses-native libsdl2"
export LIBCLANG_PATH = "${WORKDIR}/recipe-sysroot/${libdir}"

When I try to build the recipe with bitbake I get the following error:

|   thread 'main' panicked at 'Unable to find libclang: "the `libclang` 
    shared library at 
${WORKDIR}/tmp/work/corei7-64-poky-linux/dummy-reader-sdl2/
          0.1.0.AUTOINC+d2766c10a0-r0/recipe-sysroot/
          usr/lib/libclang.so.14.0.3 could not be opened: 
          libncurses.so.5: cannot open shared object file: No such file or directory"', 

${WORKDIR}/tmp/work/corei7-64-poky-linux/dummy-reader-sdl2/
          0.1.0.AUTOINC+d2766c10a0-r0/
          cargo_home/bitbake/bindgen-0.59.2/src/lib.rs:2144:31

When I look in the recipe-sysroot/usr/lib/ I can see that it is populated with lib clang.so but libncurses.so.5 is missing (there is a libncurses.so library).

Further searching revealed that the missing libncurses.so.5 is present in recipe-sysroot/lib/. If I manually add a link (i.e. ln -s ../../lib/libncurses.so.5 libncurses.so.5 I can re-run bitbake and by application builds correctly and runs on the target hardware. This is obviously a hack and I need to find a proper solution.

Note. recipe-sysroot/lib/ does not contain libclang.so

How do I configure my recipe so that either:

libclang.so

  1. libncurses.so.5 & libclang.so are populated to the same directory (either recipe-sysroot/lib/or recipe-sysroot/usr/lib/)
  2. The dependencies for libclang.so search in recipe-sysroot/lib/
mark
  • 7,381
  • 5
  • 36
  • 61
  • If anyone knows a better place to ask for Yocto support please add a comment – mark May 20 '22 at 09:59
  • Maybe with `export LD_LIBRARY_PATH = "${RECIPE_SYSROOT}/lib:${RECIPE_SYSROOT}/${libdir}"`? – Jmb May 20 '22 at 12:17
  • @jmb, I tried that but no luck. I have a workaround which involves creating the links manually in the recipe but it feels like a bodge. Surely there is a way to configure the build so that the libraries are all staged to the same directory before compilation starts. – mark May 20 '22 at 15:34
  • 1
    @mark next time you can also try the yocto mailing list, but I am not sure it will work for this kind of specific question. – Étienne Jul 19 '22 at 13:57

1 Answers1

1

My eventual solution involves manually creating links to the required libraries within the configure step of the recipe. The code below checks if the require library exists in the {WORKDIR}/usr/lib directory, if not it creates a symbolic link to the version in the {WORKDIR}/lib directory.

DEPENDS += " clang ncurses libsdl2"

USR_LIB_WORKDIR = "${WORKDIR}/recipe-sysroot/${libdir}"
BASE_LIB_WORKDIR = "${WORKDIR}/recipe-sysroot/${base_libdir}"
export LIBCLANG_PATH = "${USR_LIB_WORKDIR}"

do_configure:append() {
    if [ -f ${USR_LIB_WORKDIR}/libncurses.so.5 ];
    then
      echo "libncurses.so.5 already exists"
    else
        ln -s ${BASE_LIB_WORKDIR}/libncurses.so.5 ${USR_LIB_WORKDIR}/libncurses.so.5
    fi

    if [ -f ${USR_LIB_WORKDIR}/libtinfo.so.5 ];
    then
      echo "libtinfo.so.5 already exists"
    else
        ln -s ${BASE_LIB_WORKDIR}/libtinfo.so.5 ${USR_LIB_WORKDIR}/libtinfo.so.5
    fi
}

I am sure the recipe could be improved by extracting the test & create link operation above into a separate function but at present I am unsure how to create/call functions that take parameters in Yocto recipes.

mark
  • 7,381
  • 5
  • 36
  • 61
  • Just note that unless you are building for an x86-64 target, the clang library in "${WORKDIR}/recipe-sysroot/${libdir}" has the architecture of the target and I think it is therefore not suitable for bindgen. I used "${TMPDIR}/sysroots-components/x86_64/clang-native/usr/lib/" instead. – Étienne Jul 19 '22 at 14:38