通过github下载源码,自己编译生成的非Xilinx官方动态库,应该如何使petalinux在生成镜像时包含进去呢?
首先按照UG1144中的步骤,建立mylib:
petalinux-create -t apps --template install --name mylib --enable
然后修改<plnx-proj-root>/project-spec/meta-user/recipes-apps/mylib/ mylib.bb
文件,本文最终的包含动态库.bb文件如下:
#
# This file is the mylib recipe.
#
SUMMARY = "Simple mylib application"
SECTION = "PETALINUX/apps"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://libopencv_calib3d.so \
file://libopencv_calib3d.so.3.4 \
file://libopencv_calib3d.so.3.4.10 \
file://libopencv_core.so \
file://libopencv_core.so.3.4 \
file://libopencv_core.so.3.4.10 \
file://libopencv_features2d.so \
file://libopencv_features2d.so.3.4 \
file://libopencv_features2d.so.3.4.10 \
file://libopencv_imgcodecs.so \
file://libopencv_imgcodecs.so.3.4 \
file://libopencv_imgcodecs.so.3.4.10 \
file://libopencv_imgproc.so \
file://libopencv_imgproc.so.3.4 \
file://libopencv_imgproc.so.3.4.10 \
file://libopencv_objdetect.so \
file://libopencv_objdetect.so.3.4 \
file://libopencv_objdetect.so.3.4.10 \
file://libopencv_flann.so \
file://libopencv_flann.so.3.4 \
file://libopencv_flann.so.3.4.10 \
file://libQt5Core.so \
file://libQt5Core.so.5 \
file://libQt5Core.so.5.12 \
file://libQt5Core.so.5.12.3 \
file://libQt5Network.so \
file://libQt5Network.so.5 \
file://libQt5Network.so.5.12 \
file://libQt5Network.so.5.12.3 \
"
S = "${WORKDIR}"
TARGET_CC_ARCH += "${LDFLAGS}"
do_package_qa[noexec] = "1"
EXCLUDE_FROM_SHLIBS = "1"
INSANE_SKIP_${PN} += "ldflags"
INHIBIT_PACKAGE_DEBUG_SPLIT = "1"
INHIBIT_PACKAGE_STRIP = "1"
do_install() {
install -d ${D}${libdir}
#install -m 0755 ${S}/mylib ${D}/${bindir}
cp ${S}/*.so* ${D}${libdir}
install -d ${D}/usr/backup/library
cp ${S}/*.so* ${D}/usr/backup/library
}
FILES_${PN} += "${libdir}"
FILES_${PN} += "/usr/backup/library"
FILES_SOLIBSDEV = ""
petalinux实际上是yocto工具套壳,在遇到问题时,除了上Xilinx forum寻找答案,也可以浏览yocto的官网,见参考链接【1】。下述是可能出现的问题:
(1)
由于在.bb文件中创建了动态库备份文件夹,因此编译时会出现如下Multiple shlib providers
错误:
一种方法是,根据参考链接【2】,在.bb文件中添加代码:
do_package_qa[noexec] = "1"
EXCLUDE_FROM_SHLIBS = "1"
另一种方法是根据参考链接【3】,将这些动态库设置为PRIVATE_LIBS:
PRIVATE_LIBS += "\
动态库文件名 \
"
(2)
出现[installed-vs-shipped]
问题,是因为在do_install()
中创建了新的备份文件夹,但是FILE_${PN}
中没有添加这个文件夹。加上
INSANE_SKIP_${PN} += "installed-vs-shipped"
指令可以忽略该错误,但我们需要的${D}/usr/backup/library
不会被创建,也就不能完成备份的功能。
正确的做法是在FILE_${PN}
中添加该文件夹:
FILES_${PN} += "/usr/backup/library"
(3)
参考链接【4】yocto官网的3.13.2章节,提到了包含pre-built libraries的.bb文件的写法,因此根据该章节在.bb文件中添加如下语句:
INSANE_SKIP_${PN} += "ldflags"
INHIBIT_PACKAGE_DEBUG_SPLIT = "1"
INHIBIT_PACKAGE_STRIP = "1"
以上是包含动态库的操作,下面是包含应用程序的操作,.bb文件如下:
#
# This file is the 804 recipe.
#
SUMMARY = "Simple 804 application"
SECTION = "PETALINUX/apps"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI = "file://image_process \
file://radar_process \
file://temp/2647.jpg \
file://temp/480.jpg \
"
INSANE_SKIP_${PN} += "file-rdeps"
INSANE_SKIP_${PN} += "ldflags"
INHIBIT_PACKAGE_DEBUG_SPLIT = "1"
INHIBIT_PACKAGE_STRIP = "1"
do_package_qa[noexec] = "1"
EXCLUDE_FROM_SHLIBS = "1"
S = "${WORKDIR}"
do_install() {
install -d ${D}/${bindir}
install -d ${D}/${bindir}/config
install -d ${D}/${bindir}/data
install -d ${D}/${bindir}/temp
install -d ${D}/usr/backup/process
install -d ${D}/usr/backup/process/config
install -d ${D}/usr/backup/process/data
install -d ${D}/usr/backup/process/temp
install -m 0755 ${S}/image_process ${D}/${bindir}
install -m 0755 ${S}/radar_process ${D}/${bindir}
install -m 0755 ${S}/temp/2647.jpg ${D}/${bindir}/temp
install -m 0755 ${S}/temp/480.jpg ${D}/${bindir}/temp
install -m 0755 ${S}/image_process ${D}/usr/backup/process
install -m 0755 ${S}/radar_process ${D}/usr/backup/process
install -m 0755 ${S}/temp/2647.jpg ${D}/usr/backup/process/temp
install -m 0755 ${S}/temp/480.jpg ${D}/usr/backup/process/temp
}
FILES_${PN} += "/usr/backup/process"
(1)
由于image_process依赖于opencv库和Qt库,尽管动态库包含进了镜像之中,但是在应用程序的.bb文件中并没有显式地声明依赖库,会造成如下的问题:
一种方法是添加RDEPENDS_${PN},告知yocto应用程序在运行时的依赖库:
RDEPENDS_${PN} += “libopencv-flann libopencv-highgui”
为什么动态库名为libopencv-flann,而不是libopencv_flann?其他的动态库如何写RDEPENDS_${PN}
?本文并没有找到详细说明。
因此本文最终选择跳过该项QA检查,方法为在.bb文件中添加如下语句:
INSANE_SKIP_${PN} += “file-rdeps”
参考链接
【1】9 QA Error and Warning Messages — The Yocto Project ® 4.0.999 documentation
【2】https://stackoverflow.com/questions/64317851/yocto-recipe-for-an-application-that-uses-opencv-and-cpp
【3】https://github.com/agherzan/meta-raspberrypi/issues/498
【4】https://docs.yoctoproject.org/dev-manual/common-tasks.html?highlight=inhibit_package_strip