1

As suggested by Zac Anger, i copy this question over here:

I have a yocto recipe in which I copy/install some stuff to an image. After that, I want to add a line to the /etc/ld.so.conf file like this, so that the dynamic loader finds my library files:

do_install(){
  # install some stuff...

  echo /opt/myStuff/lib >> /etc/ld.so.conf
  ldconfig
}

During the build process I get the following error which aborts the build process:

...
| DEBUG: Python function extend_recipe_sysroot finished
| DEBUG: Executing shell function do_install
| /home/debian/Devel/myYocto/build/tmp/work/myTarget/myRecipe/1.0-r0/temp/run.do_install.3176: 203: cannot create /etc/ld.so.conf: Permission denied
| WARNING: exit code 2 from a shell command.
ERROR: Task (/home/debian/Devel/myYocto/poky/meta-myLayer/myRecipe/myRecipe.bb:do_install) failed with exit code '1'

Now to my question: How do I add a custom path to the dynamic loader by adding a line or editing the /etc/ld.so.conf file in a yocto recipe?

schande
  • 113
  • 4
  • Since `root` is needed to do as described... Perhaps consider `LD_LIBRARY_PATH` environment variable instead? https://stackoverflow.com/a/30672393/3196753 – tresf May 24 '23 at 06:34
  • 1
    You are getting the permission error because you are trying to update the file on your build machine. You want to do it for the build image rootfs, so do `echo /opt/myStuff/lib >> ${D}${sysconfdir}/ld.so.conf` instead. And, I don't think you need ldconfig(8) in your recipe. – dhanushka May 24 '23 at 06:50

1 Answers1

1

I suppose you want that addition in the /etc/ld.so.conf of your target system, but

echo /opt/myStuff/lib >> /etc/ld.so.conf

would change that file on your build host. Fortunally, this gives an error.

Your target rootfs is $D, so your file would be unter $D/etc/ld.so.conf, but more generally, the file doesn't need to be located in /etc, so you would use ${D}${sysconfdir}/ld.so.conf.

But then you experienced the problem that you can't do that in do_install(), because different receipes would generate separate ld.so.conf, leading to conflicts. Thus, better work with a ld.so.conf.d:

install -d ${D}${sysconfdir}/ld.so.conf.d/
echo /opt/myStuff/lib >> ${D}${sysconfdir}/ld.so.conf.d/myStuff.conf

Or, even better, put that file in your recipe and do

install -m 0755 ${WORKDIR}/myStuff.conf ${D}${sysconfdir}/ld.so.conf.d/

Also, don't run ldconfig on your host. Some Yocto magic will update your library cache anyhow.

Philippos
  • 13,237
  • 2
  • 37
  • 76