TipsAndTricks/PackagingNonversionedLibrary: Difference between revisions
Henry Bruce (talk | contribs) |
RossBurton (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
= How to Package an Unversioned Library = | = How to Package an Unversioned Library = | ||
Libraries in Linux systems are generally versioned so that it is possible to have multiple versions of the same library installed, which eases upgrades and support for older software. For example, suppose that in a versioned library an actual library is called "libfoo.so.1.2", a symbolic link named "libfoo.so.1" points to "libfoo.so.1.2", and a symbolic link named "libfoo.so" points to "libfoo.so.1.2". Given these conditions, when you link a binary against a library, you typically provide the unversioned file name (i.e. -lfoo to the linker). However, the linker follows the symbolic link and actually links against the versioned filename. The unversioned symbolic link is only used at development time. Consequently, the library is packaged along with the headers in the development package ${PN}-dev along with the actual library and versioned symbolic links in ${PN}. Because versioned libraries are far more common than unversioned libraries, the default packaging rules assume versioned libraries. | |||
It follows that packaging an unversioned library requires a bit of work in the recipe. By default, "libfoo.so" gets packaged into ${PN}-dev, which triggers a QA warning that a non-symlink library is in a -dev package, and binaries in the same recipe link to the library in ${PN}-dev, which triggers more QA warnings. To solve this problem, you need to package the unversioned library into ${PN} where it belongs. Following are the abridged default FILES variables in bitbake.conf: | |||
SOLIBS = ".so.*" | |||
SOLIBSDEV = ".so" | |||
FILES_${PN} = "... ${libdir}/lib*${SOLIBS} ..." | |||
FILES_SOLIBSDEV ?= "... ${libdir}/lib*${SOLIBSDEV} ..." | |||
FILES_${PN}-dev = "... ${FILES_SOLIBSDEV} ..." | |||
SOLIBS defines a pattern that matches real shared object libraries. SOLIBSDEV matches the development form (unversioned symlink). These two variables are then used in FILES_${PN} and FILES_${PN}-dev, which puts the real libraries into ${PN} and the unversioned symbolic link into PN-dev. To package unversioned libraries, you need to modify the variables in the recipe as follows: | |||
SOLIBS = ".so" | |||
FILES_SOLIBSDEV = "" | |||
The modifications cause .so to be the real library and unsets FILES_SOLIBSDEV so that no libraries get packaged into PN-dev. The changes are required because unless PACKAGES is changed, PN-dev collects files before PN. PN-dev must not collect any of the files you want in PN. | |||
Finally, loadable modules (i.e. essentially unversioned libraries that are linked at runtime using dlopen() instead of at build time) should generally be installed in a private directory. However, if they are installed in ${libdir}, then the modules can be treated as unversioned libraries. | |||
Revision as of 19:37, 18 August 2016
How to Package an Unversioned Library
Libraries in Linux systems are generally versioned so that it is possible to have multiple versions of the same library installed, which eases upgrades and support for older software. For example, suppose that in a versioned library an actual library is called "libfoo.so.1.2", a symbolic link named "libfoo.so.1" points to "libfoo.so.1.2", and a symbolic link named "libfoo.so" points to "libfoo.so.1.2". Given these conditions, when you link a binary against a library, you typically provide the unversioned file name (i.e. -lfoo to the linker). However, the linker follows the symbolic link and actually links against the versioned filename. The unversioned symbolic link is only used at development time. Consequently, the library is packaged along with the headers in the development package ${PN}-dev along with the actual library and versioned symbolic links in ${PN}. Because versioned libraries are far more common than unversioned libraries, the default packaging rules assume versioned libraries.
It follows that packaging an unversioned library requires a bit of work in the recipe. By default, "libfoo.so" gets packaged into ${PN}-dev, which triggers a QA warning that a non-symlink library is in a -dev package, and binaries in the same recipe link to the library in ${PN}-dev, which triggers more QA warnings. To solve this problem, you need to package the unversioned library into ${PN} where it belongs. Following are the abridged default FILES variables in bitbake.conf:
SOLIBS = ".so.*" SOLIBSDEV = ".so" FILES_${PN} = "... ${libdir}/lib*${SOLIBS} ..." FILES_SOLIBSDEV ?= "... ${libdir}/lib*${SOLIBSDEV} ..." FILES_${PN}-dev = "... ${FILES_SOLIBSDEV} ..."
SOLIBS defines a pattern that matches real shared object libraries. SOLIBSDEV matches the development form (unversioned symlink). These two variables are then used in FILES_${PN} and FILES_${PN}-dev, which puts the real libraries into ${PN} and the unversioned symbolic link into PN-dev. To package unversioned libraries, you need to modify the variables in the recipe as follows:
SOLIBS = ".so" FILES_SOLIBSDEV = ""
The modifications cause .so to be the real library and unsets FILES_SOLIBSDEV so that no libraries get packaged into PN-dev. The changes are required because unless PACKAGES is changed, PN-dev collects files before PN. PN-dev must not collect any of the files you want in PN.
Finally, loadable modules (i.e. essentially unversioned libraries that are linked at runtime using dlopen() instead of at build time) should generally be installed in a private directory. However, if they are installed in ${libdir}, then the modules can be treated as unversioned libraries.