create symbolic link in bitbake recipe
Asked Answered
S

7

11

I have a .bbappend recipe that I need to create a symbolic link in my system.

This is how it looks like now:

bernardo@bernardo-ThinkCentre-Edge72:~/yocto/genericx86-64-rocko-18.0.0/meta-datavision/recipes-devtools/oracle-java$ cat oracle-jse-jdk_1.7.0.bbappend 
FILES_${PN} += "/lib64/ld-linux-x86-64.so.2"

do_install_append() {
    install -d ${D}/lib64
    ln -s ${D}/lib/ld-2.26.so ${D}/lib64/ld-linux-x86-64.so.2 
}

However, only the directory /lib64 is created in the sysroot. The symlink /lib64/ld-linux-x86-64.so.2 is not being generated.

What changes should I make in my recipe in order to have this symlink correctly created?

Skirl answered 9/1, 2018 at 11:50 Comment(0)
C
8

Try to avoid usage of absolute paths:

do_install_append() {
    install -d ${D}/lib64
    cd ${D}/lib64
    ln -s ../lib/ld-2.26.so ld-linux-x86-64.so.2 
}
Crumpled answered 9/1, 2018 at 15:26 Comment(4)
works like a charm! thanks so much!!!!!! would you mind explaining a little further why I needed to cd before creating the symlink? thanks again!Skirl
First of all, D variable contains an absolute path to your deploy dir, so on your target system it would point to something like /path/to/yocto/dir/build/tmp/work/.../lib64/... that is obviously an invalid location. Also, it is common to specify relative path for symlinks, it helps for example in sharing libraries in binary format.Fineberg
Regarding your case, I'm not quite sure why haven't you seen the link in resulting package (you haven't seen it, or it was an error during the build?), but as I mentioned above it isn't common to specify an absolute path in ln. I'm not even sure it is valid to use an absolute path as the link_name for ln.Fineberg
I have similar problem as OP, no link file gets installed. I've tried creating the link as suggested in this answer. But still get no link file installed. How does creating the link a certain way result in the file getting installed? I don't see how this answer fixes the OP's problem. And what's wrong with absolute paths? Not like these files are going to be moved around.Verse
P
21

The cleanest solution is to use the "-r" flag:

do_install_append() {
    install -d ${D}/lib64
    ln -s -r ${D}/lib/ld-2.26.so ${D}/lib64/ld-linux-x86-64.so.2 
}

From the gnu ln man page:

       -r, --relative            create symbolic links relative to link location
Panek answered 28/6, 2018 at 21:7 Comment(0)
M
9

For Yocto 2.3 to 3.4:

do_install_append() {
    install -d ${D}/lib64
    lnr ${D}/lib/ld-2.26.so ${D}/lib64/ld-linux-x86-64.so.2 
}

For Yocto 4.0+ (or if your host system has coreutils 8.16+):

do_install:append() {
    install -d ${D}/lib64
    ln --relative --symbolic ${D}/lib/ld-2.26.so ${D}/lib64/ld-linux-x86-64.so.2 
}

Alternatively, you can also inherit relative_symlinks which will turn any absolute symlinks into relative ones, but this is less commonly used than lnr.

Cf:

Meddlesome answered 6/9, 2019 at 15:11 Comment(2)
lnr has been removed in 4.0 docs.yoctoproject.org/migration-guides/…Batman
Hello @Christopher, your override syntax has to be updated in Yocto release 3.4 and 4.0+ docs.yoctoproject.org/4.0.10/migration-guides/… do_install:append()Prodigious
C
8

Try to avoid usage of absolute paths:

do_install_append() {
    install -d ${D}/lib64
    cd ${D}/lib64
    ln -s ../lib/ld-2.26.so ld-linux-x86-64.so.2 
}
Crumpled answered 9/1, 2018 at 15:26 Comment(4)
works like a charm! thanks so much!!!!!! would you mind explaining a little further why I needed to cd before creating the symlink? thanks again!Skirl
First of all, D variable contains an absolute path to your deploy dir, so on your target system it would point to something like /path/to/yocto/dir/build/tmp/work/.../lib64/... that is obviously an invalid location. Also, it is common to specify relative path for symlinks, it helps for example in sharing libraries in binary format.Fineberg
Regarding your case, I'm not quite sure why haven't you seen the link in resulting package (you haven't seen it, or it was an error during the build?), but as I mentioned above it isn't common to specify an absolute path in ln. I'm not even sure it is valid to use an absolute path as the link_name for ln.Fineberg
I have similar problem as OP, no link file gets installed. I've tried creating the link as suggested in this answer. But still get no link file installed. How does creating the link a certain way result in the file getting installed? I don't see how this answer fixes the OP's problem. And what's wrong with absolute paths? Not like these files are going to be moved around.Verse
J
1

I had a look at how other recipes create links in the rootfs, and most seem to do it this way:

ln -sf /data/etc/bluetooth/main.conf ${D}/${sysconfdir}/bluetooth/main.conf

This command in the recipe will create the following link on the device:

/# ls -al /etc/bluetooth/main.conf
lrwxrwxrwx 1 root root 29 Sep 11 15:34 /etc/bluetooth/main.conf -> /data/etc/bluetooth/main.conf

You use the full, Yocto-generated path when creating the link, but you make it point to the "final" location in the rootfs.

This way you can use "absolute" paths and won't have to change the working directory in the recipe.

Jeanicejeanie answered 11/9, 2018 at 15:37 Comment(0)
E
1

As of 2022-01-19 this seems to be the only way to get it to work (adapt to the filenames needed):

do_install() {
    install -d ${D}${libdir}
    install -m 0644 ${S}/libmine.so.0 ${D}${libdir}/
    lnr ${D}${libdir}/libmine.so.0 ${D}${libdir}/libmine.so
}

FILES_${PN} += " \
    ${libdir}/libmine.so.0 \
    ${libdir}/libmine.so \
"

FILES_SOLIBSDEV = ""
INSANE_SKIP_${PN} += "dev-so"
Emelinaemeline answered 19/1, 2022 at 14:49 Comment(0)
B
0

You can do:

ln -s ../lib/ld-2.26.so ${D}/lib64/ld-linux-x86-64.so.2

or if you don't require the symbolic-link until after your target system has booted up (i.e. it's not a dependency of other packages you are building) you can also do:

ln -s /lib/ld-2.26.so ${D}/lib64/ld-linux-x86-64.so.2

ln doesn't care if your target is valid or exists when a symbolic-link is created. It will become valid after you boot your target-system (or somehow mount this filesystem to /). But indeed, relative links are recommended.

Barlow answered 28/9, 2018 at 12:38 Comment(0)
O
0
do_install_append () {
    install -d 0755 ${D}/dir
    install -d 0755 ${D}/dir/subdir
    cd ${D}/dir/subdir
    ln -sf /source_so_the_symbilic_link <name_of_the_symbolic_link>
} 
FILES_${PN} += "/dir" 
Otiose answered 11/1, 2021 at 16:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.