Somewhat new Yocto. Trying to build a library that will be included into the filesystem. I used a devtool to create initial recipe. The library does have a Makefile however it (the library) was used in a different project and all the variables, including build and install directories, are tailored towards an original project. Here are a few questions.
How do I tell Yocto through a Makefile where to build the files for the library?
How do I tell Yocto through a Makefile where to install the library files?
I have to apologize since I can't post the the source as well as the Makefile for the library online due to the nature of the project. But I would really appreciate any pointers or maybe samples of library build instructions for Yocto.
By default yocto recipe have some function to configure, compile and copy the filesand libs to rootfs.
do_configure(){
./configure
..
..
}
do_compile(){
make
..
..
}
do_install(){
install -d ${S}${libdir} # create usr/lib dir in rootfs
install -d ${S}${libdir} # create usr/bin dir in rootfs
install -m 0777 ${S}/lib.so ${D}${libdir} # copies all your libs to usr/lib
install -m 0777 ${S}/binaries ${D}${bindir} # copies all your binaries to usr/bin
}
FILES_{PN} +="${libdir}/*"
FILES_{PN} +="${bindir}/*"
Note:install means copy
S = yoctosource/build/tme/work/cortex-a8/your package
D = yoctosource/build/tme/work/cortex-a8/image dir for rootfs
Related
Some years ago on Ubuntu 16.0.4 I've used this library: git clone https://github.com/Beckhoff/ADS and using only the make command I got build, compile and finally on the main directory I found a file called AdsLib-Linux.a and maybe nothing more than this.
Now I'm on Ubuntu 20.04 I need this library once again but this times make dosn't produce the same output and looking forth to the ReadMe instructions I finally used that instead of make:
meson build
ninja -C build
That now create a new directory build but no .a file as before on the root directory. Instead a new file in the build directory libADSLib.a is there. The same thing happens using right the make command.
Maybe the author changed over the years something on the config files or the behavior of the tools have changed, but I cannot get the former file anymore and I need it for other referencing code that now is not executing anymore.
Looking to the MakeFile I found that in the example folder, differently from the one on the parent directory, the MakeFile has something like that:
$(warning ATTENTION make is deprecated and superseeded by meson)
...
${PROGRAM}: LIB_NAME = ../AdsLib-${OS_NAME}.a
...
But all i've tried reading the guides on meson and ninja about setup, configure, build, and so on, did not produce anymore that file.
I've tried also to first build and then copy all files form the example folder to the parent directory and then build again, but again no .a file there.
How's the right way to configure the build process corectly so that this -Linux.a file is created. Or if not possibile anymore, what does it now produce I can use instead of what produced before?
Meson is a build system generator, similar to CMake or somewhat like ./configure, you need to run meson, then run ninja to actually build something.
You need to run both meson and ninja:
meson setup builddir
ninja -C builddir
Once you do that successfully, there will be a libAdsLib.a inside the builddir directory.
Let me correct a bit #dcbaker, according to their README you should setup build as build directory:
# configure meson to build the library into "build" dir
meson build
# let ninja build the library
ninja -C build
Of course, in general, it shouldn't be specific, but their example code is written in a weird way so this path is hard-coded. So, to use the example:
# configure meson to build example into "build" dir
meson example/build example
# let ninja build the example
ninja -C example/build
# and run the example
./example/build/example
About the library: it's now libAdsLib.a and produced in build directory. The name is set here and it's now in linux naming style, the old one - not. So, you have options:
Update your configuration/build files (Makefile?) where you use it
Copy or make symbolic link, e.g.
$ ln -s <>/build/libAdsLib.a <target_path>/AdsLib-Linux.a
Above it's very dependent on your development environment, do you have installation or setup scripts for it? do you permissions to modify/configure parameters for target application? do you need to support both old and new names? - many questions not related to original question about meson.
I installed the latest Cygwin on my Windows 7 machine: version 2.893 (64-bits). I made sure I included cmake, i.e. I was able to add several packages by running the Cygwin net release setup program again, after doing the first installation. I then tried to use cmake and made sure I invoked it from the bin directory:
user008#L0147816 /bin
$ ./cmake
CMake Error: Could not find CMAKE_ROOT !!!
CMake has most likely not been installed correctly.
Modules directory not found in
//share/cmake-3.6.2
Usage
cmake [options] <path-to-source>
cmake [options] <path-to-existing-build>
Specify a source directory to (re-)generate a build system for it in the
current working directory. Specify an existing build directory to
re-generate its build system.
Run 'cmake --help' for more information.
I don't know where the build directory could be. I'm relatively new to Cygwin. I hope somebody has found a solution for getting cmake installed and working properly under Cygwin.
This looks cmake 101.
Assuming you want to just build a software download from somewhere
eg gl2ps:
# choosing a test area
$ cd /tmp
# downloading source
$ wget http://geuz.org/gl2ps/src/gl2ps-1.4.0.tgz
# expanding source code
$ tar -xf gl2ps-1.4.0.tgz
$ ls gl2ps-1.4.0-source/
CMakeLists.txt COPYING.LGPL gl2ps.h gl2ps.tex gl2psTestSimple.c
COPYING.GL2PS gl2ps.c gl2ps.pdf gl2psTest.c README.txt
# preparing a build area
$ mkdir build
$ cd build
# invoking cmake and pointing to the source directory
$ cmake ../gl2ps-1.4.0-source/
-- The C compiler identification is GNU 7.3.0
[cut ...]
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/build
# running the build
$ make
Scanning dependencies of target shared
[ 11%] Building C object CMakeFiles/shared.dir/gl2ps.o
...
[ 88%] Building C object CMakeFiles/gl2psTestSimple.dir/gl2psTestSimple.o
[100%] Linking C executable gl2psTestSimple.exe
[100%] Built target gl2psTestSimple
Instead for learning how to build with cmake, go to
https://cmake.org/cmake-tutorial/
Here a solution I just found.
Let's name 3 directories:
{cygwin64-path}/bin/: cmake.exe is here.
{cygwin64-path}/usr/share/: cmake module directory (such as cmake-3.20.0) is here.
{cygwin64-path}/share/: cmake.exe trying to find cmake-module-directory here, but it doesn't exist.
It's wired because cygwin install cmake-module-directory in {cygwin64-path}/usr/share/, but cmake.exe looks for the directory in {cygwin64-path}/share/.
So solution is simple. Each one below works.
METHOD 1: Create the directory {cygwin64-path}/share/ and copy all relevant directories and files from {cygwin64-path}/usr/share/ to the new directory.
METHOD 2: Create a Symbolic links {cygwin64-path}/share/ to {cygwin64-path}/usr/share/.
In windows 10 Administrator cmd.exe: mklink /J share usr\share and all works.
Or use WSL or Cygwin64 Terminal: ln -s usr/share share
I am building binaries for our custom board(iMX7) using Yocto-morty. I need some libraries such as UTF-32.so, UTF-16.so, UTF-7.so from glibc package for bluetooth file tranfer. But these libraries are not available in the rootfs, only files available under /usr/lib/gconv are gconv-modules and ISO8859-1.so. So I am trying to add these libraries by adding new bbappend file glibc_2.24.bbappend with the following content
FILES_${PN} += "${libdir}/gconv/*"
do_install_locale_append() {
cp -r ${dest}${libdir}/gconv ${D}${libdir}/
}
But it results in the following error:
ERROR: glibc-2.24-r0 do_populate_sysroot: The recipe glibc is trying to install files into a shared area when those files already exist. Those files and their manifest location are:
build_dir/tmp/sysroots/esomimx7d/usr/lib/gconv/ISO-2022-CN.so Matched in b'manifest-esomimx7d-glibc-locale.populate_sysroot'
build_dir/tmp/sysroots/esomimx7d/usr/lib/gconv/ARMSCII-8.so Matched in b'manifest-esomimx7d-glibc-locale.populate_sysroot'
......
Then I tried to remove the glibc-locale from the image but due to some dependency issues I could not do that.
Could anyone help me to add the above mentioned libraries to the rootfs?
The error is telling you the answer to your problem. Those files are part of the glibc-locale recipe, so you just need to install the right packages into the rootfs.
$ oe-pkgdata-util find-path \*/UTF-7.so
glibc-gconv-utf-7: /usr/lib/gconv/UTF-7.so
So you need to add glibc-gconv-utf-7 (or -utf-32, etc) to your image.
You can remove thm and compile again it will work.
rm build_dir/tmp/sysroots/esomimx7d/usr/lib/gconv/ISO-2022-CN.so
rm build_dir/tmp/sysroots/esomimx7d/usr/lib/gconv/ARMSCII-8.so
This is for work around only we need for perminant sol.
These files are belongs to glibc-locale so you need to install the required packages.
$ oe-pkgdata-util find-path */UTF-7.so
glibc-gconv-utf-7:> /usr/lib/gconv/UTF-7.so
Add the glibc-gconv-utf-7 (or -utf-32, etc) to recipe image(e.g core-image-minimal).
I have custom image created based on the yocto project to run on a Arm cortex A9 processor which is on a Zynq. I compile my application with a cross-compiler on my Linux machine, and trying to run it on Arm. But it gives an error asking that it cannot find the libstdc++6 library. This library is really not included on my image. When I manually copy the libstdc++.so.6 to /lib folder on target, it runs successfully. Hence I want to build my image to include that library itself. I tried creating a recipe like seen below
DESCRIPTION = "Copy necessary lib files to rootfs/lib directory"
LICENSE = "CLOSED"
PACKAGE_ARCH = "all"
SRC_URI += " \
file://libstdc++.so.6 \
file://libstdc++.so.6.0.22 \
"
do_install () {
install -d ${D}${base_libdir}/
install -m 755 ${WORKDIR}/libstdc++.so.6 ${D}${base_libdir}/
install -m 755 ${WORKDIR}/libstdc++.so.6.0.22 ${D}${base_libdir}/
}
FILES_${PN} += " \
${base_libdir}/libstdc++.so.6 \
${base_libdir}/libstdc++.so.6.22 \
"
but it gives the error that those libraries already exists in a shared area. But I cannot figure out how to copy from that shared are to /lib directory in image. Here is the error:
ERROR: my-recipe-1.0-r0 do_packagedata: The recipe my-recipe is trying
to install files into a shared area when those files already exist.
Those files and their manifest location are:
/home/myUser/REPOS/my-platform/build/tmp-glibc/sysroots/my-board-xc7z030/pkgdata/runtime-reverse/libstdc++6
Matched in b'manifest-my-board-xc7z030-gcc-runtime.packagedata'
/home/myUser/REPOS/my-platform/build/tmp-glibc/sysroots/my-board-xc7z030/pkgdata/runtime-reverse/libstdc++-dev Matched in b'manifest-my-board-xc7z030-gcc-runtime.packagedata' Please
verify which recipe should provide the above files.
So what is the correct way of putting the standard library into the image?
Thanks!
You don't need to explicitly add libraries to your image, if you've got an application that links againts it (at least as you're linking normally to them).
Instead, write a recipe for your C++ application. In the case of libstdc++.so.6, this runtime dependency will be automatically detected for you.
Had it been another library, you'd need add it's recipe to you build time dependencies, DEPENDS; the runtime part would still be handled automatically.
Update:
If you want to add libstdc++.so.6 to your image, without adding any C++ application; just add
IMAGE_INSTALL_append = " libstdc++6"
How do I include the linux kernel headers as part of the SDK package in Yocto?
I'm using Yocto 1.8 (fido) in an embedded project and want to do out-of-tree kernel module development. Currently, I can build my kernel modules (apart from bitbake) by pointing my $KERNEL_PATH to the poky/build/tmp/work-shared/<machine>/kernel-source/ directory when I run make. I don't want to do this in the long term, however, since others need to easily build the modules without installing and building a full image from bitbake.
I can generate an SDK using bitbake myimage -c populate_sdk. However, this doesn't include the kernel headers (all I ever see is sysroots/<mach>/usr/include/linux). How do I cause the kernel headers to be included in the SDK package? Also, I don't want the kernel headers to show up as part of my target image.
[Edit]
My image recipe is as follows:
EXTRA_IMAGE_FEATURES_append = " eclipse-debug debug-tweaks"
TOOLCHAIN_HOST_TASK_append = " nativesdk-cmake"
IMAGE_INSTALL = "packagegroup-core-boot ${CORE_IMAGE_EXTRA_INSTALL} util-linux kernel-modules netbase busybox base-passwd base-files sysvinit initscripts bash gdbserver strace sysfsutils dtc gawk ethtool grep sed wget iptables oprofile net-tools dropbear rsync stress-ng rt-tests i2c-tools"
inherit core-image
The kernel I'm using is linux-altera-ltsi-rt in the meta-altera layer.
From the fido release, the handling of kernel builds has been changed. In previous releases, you could usually just skip down to the usage example below.
In fido or any 1.8+, if you want the kernel src and build system available in the SDK, you should add
TOOLCHAIN_TARGET_TASK_append = " kernel-devsrc"
to your image recipe. That will ensure that the new, kernel-devsrc package is installed into your toolchain.
The procedure below is just to ensure that the rest of the workflow is fully understood (even though it's not strictly part of the original question).
Usage Example
Lets assume a module Makefile as follows:
obj-m += hello-1.o
all:
make -C $(KERNEL_SRC) M=$(PWD) modules
clean:
make -C $(KERNEL_SRC) M=$(PWD) clean
Example taken from The Linux Kernel Module Programming Guide (Note that the actual commands needs to have a tab character for indentation).
Then you'll have to define KERNEL_SRC to be sysroots/<mach>/usr/src/kernel/, either in the Makefile, or from your make call. (Using a variable like KERNEL_SRC will ensure that your module recipe automatically picks the right location when building using bitbake).
To manually build your kernel module:
Source the environment-* file for your SDK.
Go to you modules directory.
KERNEL_SRC=<sdk-install-path>/sysroots/<mach>/usr/src/kernel LDFLAGS="" make However, this will fail, as fixdep can't be found. We'll fix this manually.
cd <sdk-install-path>/sysroots/<mach>/usr/src/kernel
make modules_prepare
If this needs to be run with sudo, be sure to source the environment file in the sudo environment: sudo bash -c "source <sdk-install-path>/environment-setup-<mach> && make modules_prepare"
Go back to your modules directory.
KERNEL_SRC=<sdk-install-path>/sysroots/<mach>/usr/src/kernel LDFLAGS="" make
This should now allow you to build your modules.
If you don't have the kernel source under sysroots/<mach>/usr/src/kernel/, we'll have to look into that.
anders answer is very good, but in recent versions of yocto the way to add kernel-devsrc seems to be
IMAGE_INSTALL += "kernel-devsrc"
which I found here: https://www.mail-archive.com/yocto#yoctoproject.org/msg36448.html
With Yocto Zeus (3.0.x) add this to your image recipe:
TOOLCHAIN_TARGET_TASK += "kernel-devsrc"
EDIT: Same for Gatesgarth (3.2.x) but the make scripts command has a new host dependency to libyaml-dev