yocto有现成的sdk配方指令,例如
bitbake xxxx-image -c populate_sdk
可生成系统默认存在的开发工具,如果想加入自定义的动态库可用如下方法
在系统中加入版本号接口,本地编写代码并确定能编译成动态库,生成动态库的makefile如下
SOURCES = fubversion.cpp
OBJS = $(patsubst %.cpp, %.o, $(SOURCES))
CFLAGS := -Wall -O3 -std=c++0x
# INC_PATH =
# LIB_PATH =
LIB = libfubversion.so
all: $(LIB)
$(OBJS): $(SOURCES)
$(CXX) $(CFLAGS) -fpic -c $< -o $@ $(INC_PATH) $(LIB_PATH)
$(LIB): $(OBJS)
rm -f $@
$(CXX) -shared -o $@ $(OBJS)
rm -f $(OBJS)
tags:
ctags -R *
clean:
rm -f $(OBJS) $(TARGET) $(LIB)
然后将其放入yocto系统里,按照如下方法写bb文件,此文件调试后未整理,可能存在冗余
DESCRIPTION = "fub version library"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
PR = "1"
SRC_URI = "file://source-code \
file://patch \
file://source-code/libfubversion.so"
# DEPENDS = "glib-2.0"
S = "${WORKDIR}/source-code/"
do_compile() {
make
}
do_install() {
install -d ${D}/usr/lib
cp ${WORKDIR}/source-code/libfubversion.so ${WORKDIR}/source-code/libfubversion.so.${PR}
install -m 0755 ${WORKDIR}/source-code/libfubversion.so.${PR} ${D}/usr/lib
install -m 0755 ${WORKDIR}/source-code/libfubversion.so ${D}/usr/lib
cd ${D}/usr/lib/
ln -sf libfubversion.so.${PR} libfubversion.so
install -d ${D}/usr/include
install -m 0644 ${WORKDIR}/source-code/fubversion.h ${D}/usr/include/
}
INHIBIT_PACKAGE_STRIP = "1"
FILES_${PN} += "${libdir}/*.so"
FILES_${PN}-dbg += "${libdir}/.debug"
FILES_SOLIBSDEV = ""
INSANE_SKIP_${PN} = "dev-so"
BBCLASSEXTEND = "native nativesdk"
此处有几个关键的字段
该字段可将相关动态库生成到sdk中
BBCLASSEXTEND = "native nativesdk"
在SDK里还需要一个头文件,此处的头文件的安装不规范,但可以使用
到此,将一个包含自定义的动态库生成到sdk已经完成了,但动态库需要同时放到文件系统中,编译系统指令,如
bitbake xxxx-image
将动态库编译到文件系统规则多一些,如
其中.so为链接文件不可少,否者会提示链接文件缺失,大概如下一类错误
QA Issue: non -dev/-dbg/-nativesdk package contains symlink .so
QA Issue: -dev package contains non-symlink .so
在do_instll制作.so链接文件和对应的动态库后,不会自动将链接文件和动态库一并生成到文件系统里
在fubversion配方的image文件夹里是存在.so和动态链接文件的,但是在最终的文件系统却没有.so链接文件
这与do_package_qa一类的规则有关,解决办法
FILES_${PN} += "${libdir}/*.so"
FILES_${PN}-dbg += "${libdir}/.debug"
FILES_SOLIBSDEV = ""
INSANE_SKIP_${PN} = "dev-so"
此时才会将.so链接文件和对应的动态链接库都安装到文件系统里
上边说的头文件的问题在这里也有,就是会将头文件也安装到文件系统里,这是不需要的,以后在加入sdk头文件的安装方法
文件系统完成,系统的镜像也同步好了,测试验证
写一个测试app,makefile,读取版本号
makefile
# INCLUDE = -I $(SDK_ROOT_DIR)/usr/include
LIBS = -lversion
LDFLAGS += $(LIBS)
CPPFLAGS += $(INCLUDE)
TARGET = app_get_version
TARGET_DIR = .
SOURCES = app.cpp
OBJ_FILES = $(patsubst %.cpp, %.o, $(SOURCES))
all: check_env compile link
check_env:
@echo "[$(TARGET)]: Build Start..."
@mkdir -p $(TARGET_DIR)
@echo ${CXX}
compile: $(OBJ_FILES)
link:
@echo "[$(TARGET)]: Linking ..."
@$(CXX) $(OBJ_FILES) $(LDFLAGS) -o $(TARGET_DIR)/$(TARGET)
rm -f $(OBJ_FILES)
@echo "[$(TARGET)]: Build done!"
#complie step 1:
$(OBJ_FILES): %.o: %.cpp
@echo "[$(TARGET)]: Compiling $(notdir $^) ..."
@$(CXX) -c $(CPPFLAGS) $< -o $@
clean:
@rm -rf $(OBJ_FILES) $(TARGET_DIR)/$(TARGET)
@echo "[$(TARGET)]: Clean Finish!"
应用程序就无需关心版本号的管理怎么实现的,通过非常简单的sdk接口获得版本号达到目的
#include <fubversion.h>
#include <iostream>
#include <string>
int main ()
{
std::string sVerBuff;
sVerBuff.clear();
sVerBuff = VersionInfo::GetInstance()->GetVersionInfo("ro.build.fub.version");
printf ("%s \n", sVerBuff.c_str());
return 0;
}
在更新的yocto中又遇到了如下问题
do_package_qa: QA Issue: No GNU_HASH in the elf binary: '/home/qiuhui/imx8_4.16/build-mek/tmp/work/aarch64-poky-linux/fubversion/0.1-1/packages-split/fubversion/usr/lib/libfubversion.so.1' [ldflags]
可加入如下命令解决
TARGET_CC_ARCH += "${LDFLAGS}"
同时还查到如下命令,此命令未验证
ERROR_QA_remove = "ldflags"
在做另一个limessage.so的时候又遇到了另一个问题
ERROR: nativesdk-libmessage-0.1-1 do_package: QA Issue: nativesdk-libmessage: Files/directories were installed but not shipped in any package:
/usr
/usr/include
/usr/lib
/usr/include/manager.h
/usr/include/GDef.h
/usr/include/message.h
/usr/include/uart.h
/usr/include/EventCenter.h
/usr/include/TimerControl.h
/usr/include/Timer.h
/usr/lib/libfubversion.so
/usr/lib/libmessage.so.1
/usr/lib/libmessage.so
Please set FILES such that these items are packaged. Alternatively if they are unneeded, avoid installing them or delete them within do_install.
nativesdk-libmessage: 13 installed and not shipped files. [installed-vs-shipped]
ERROR: nativesdk-libmessage-0.1-1 do_package: Fatal QA errors found, failing task.
ERROR: nativesdk-libmessage-0.1-1 do_package: Function failed: do_package
ERROR: Logfile of failure stored in: /home/timotheus/ext_sdb/hm02/krogoth/build-wayland-e115-arhud/tmp/work/x86_64-nativesdk-pokysdk-linux/nativesdk-libmessage/0.1-1/temp/log.do_package.12245
ERROR: Task 11 (virtual:nativesdk:/home/timotheus/ext_sdb/hm02/krogoth/sources/meta-autofuture/recipes-autofuture/application/libmessage_0.1.bb, do_package) failed with exit code '1'
加入
INSANE_SKIP_${PN} += "installed-vs-shipped"
如果是想编译到文件系统而非SDK的话则在以上基础去掉,不然单独编译通过但编译镜像的时候无法通过
BBCLASSEXTEND = "native nativesdk"
编译到系统镜像的时候可以在build/conf/local.conf加入
IMAGE_INSTALL_append += "libmessage "
文中相关代码