在Yocto中,如何同时打包带版本号的共享库(包括符号链接)和不带版本号的共享库?

编程语言 2026-07-08

在我的 CMake 项目中,我既在为它创建版本化的共享库(包含 symlinks),也创建未版本化的共享库,分别是 libUnversioned.solibVersioned.so -> libVersioned.so.1.0.0libVersioned.so.1.0.0

在Yocto对上述构建好的库进行打包时,我遇到了如下错误

错误

do_package_qa: QA Issue: non -dev/-dbg/nativesdk- package abc contains symlink .so 'libVersioned.so'

Yocto配方 - 打包部分

SOLIBS = ".so"
FILES_SOLIBSDEV = ""
FILES:${PN}-dev += " \
    ${includedir}/abc \
    ${libdir}/cmake \
"

FILES:${PN} += " \
    ${libdir}/libUnversioned* \
    ${libdir}/libVersioned* \
"

我希望打包包含下列文件

libUnversioned.so
libVersioned.so -> libVersioned.so.1.0.0
libVersioned.so.1.0.0

解决方案

你不需要手动拷贝这些文件。安装版本化和未版本化的文件是很常见的做法,只要你的构建系统配置正确,Yocto就会为你完成。

一个具有简单配方的库是 libuv。该bb文件位于 libuv.bb:

我有一个我在公开的GitHub上使用的“基础” cmake文件:公开可用。你只需要:

# project, cmake standard stuff
...

add_library(${PROJECT_NAME} SHARED src/hello-world.cpp src/bar.cpp) 

### Bitbake needs the following ###

set_target_properties(${PROJECT_NAME} PROPERTIES 
  VERSION ${PROJECT_VERSION}
  SOVERSION ${PROJECT_VERSION_MAJOR})

# Destination should be inferred from type of TARGETS, still set 
# expliciticly just to be safe and saw it elsewhere
# See: https://cmake.org/cmake/help/latest/command/install.html#targets
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

然后该配方只需要 inherit cmake。对于Autotools和 make,你也可以用类似的方法来完成。

LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=30d33c8196b78acbed849e82bc3b6b18"

SRC_URI = "git://github.com/you/whatever.git"
SRCREV = "d989902ac658b4323a4f4020446e6f4dc449e25c"

inherit cmake

S = "${WORKDIR}/git"

备选方案

What you are doing is correct, technically, but that is not how Yocto is designed.

Yocto is designed to ship .so files in -dev package, and since you changed SOLIBS to force .so in the ${PN} package, you need to force skip the QA error:

INSANE_SKIP:${PN} = "dev-so"
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章