libraries.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. .. SPDX-License-Identifier: CC-BY-SA-2.0-UK
  2. Working With Libraries
  3. **********************
  4. Libraries are an integral part of your system. This section describes
  5. some common practices you might find helpful when working with libraries
  6. to build your system:
  7. - :ref:`How to include static library files
  8. <dev-manual/libraries:including static library files>`
  9. - :ref:`How to use the Multilib feature to combine multiple versions of
  10. library files into a single image
  11. <dev-manual/libraries:combining multiple versions of library files into one image>`
  12. - :ref:`How to install multiple versions of the same library in parallel on
  13. the same system
  14. <dev-manual/libraries:installing multiple versions of the same library>`
  15. Including Static Library Files
  16. ==============================
  17. If you are building a library and the library offers static linking, you
  18. can control which static library files (``*.a`` files) get included in
  19. the built library.
  20. The :term:`PACKAGES` and
  21. :term:`FILES:* <FILES>` variables in the
  22. ``meta/conf/bitbake.conf`` configuration file define how files installed
  23. by the :ref:`ref-tasks-install` task are packaged. By default, the :term:`PACKAGES`
  24. variable includes ``${PN}-staticdev``, which represents all static
  25. library files.
  26. .. note::
  27. Some previously released versions of the Yocto Project defined the
  28. static library files through ``${PN}-dev``.
  29. Here is the part of the BitBake configuration file, where you can see
  30. how the static library files are defined::
  31. PACKAGE_BEFORE_PN ?= ""
  32. PACKAGES = "${PN}-src ${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}"
  33. PACKAGES_DYNAMIC = "^${PN}-locale-.*"
  34. FILES = ""
  35. FILES:${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \
  36. ${sysconfdir} ${sharedstatedir} ${localstatedir} \
  37. ${base_bindir}/* ${base_sbindir}/* \
  38. ${base_libdir}/*${SOLIBS} \
  39. ${base_prefix}/lib/udev ${prefix}/lib/udev \
  40. ${base_libdir}/udev ${libdir}/udev \
  41. ${datadir}/${BPN} ${libdir}/${BPN}/* \
  42. ${datadir}/pixmaps ${datadir}/applications \
  43. ${datadir}/idl ${datadir}/omf ${datadir}/sounds \
  44. ${libdir}/bonobo/servers"
  45. FILES:${PN}-bin = "${bindir}/* ${sbindir}/*"
  46. FILES:${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \
  47. ${datadir}/gnome/help"
  48. SECTION:${PN}-doc = "doc"
  49. FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}"
  50. FILES:${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \
  51. ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \
  52. ${datadir}/aclocal ${base_libdir}/*.o \
  53. ${libdir}/${BPN}/*.la ${base_libdir}/*.la \
  54. ${libdir}/cmake ${datadir}/cmake"
  55. SECTION:${PN}-dev = "devel"
  56. ALLOW_EMPTY:${PN}-dev = "1"
  57. RDEPENDS:${PN}-dev = "${PN} (= ${EXTENDPKGV})"
  58. FILES:${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a"
  59. SECTION:${PN}-staticdev = "devel"
  60. RDEPENDS:${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})"
  61. Combining Multiple Versions of Library Files into One Image
  62. ===========================================================
  63. The build system offers the ability to build libraries with different
  64. target optimizations or architecture formats and combine these together
  65. into one system image. You can link different binaries in the image
  66. against the different libraries as needed for specific use cases. This
  67. feature is called "Multilib".
  68. An example would be where you have most of a system compiled in 32-bit
  69. mode using 32-bit libraries, but you have something large, like a
  70. database engine, that needs to be a 64-bit application and uses 64-bit
  71. libraries. Multilib allows you to get the best of both 32-bit and 64-bit
  72. libraries.
  73. While the Multilib feature is most commonly used for 32 and 64-bit
  74. differences, the approach the build system uses facilitates different
  75. target optimizations. You could compile some binaries to use one set of
  76. libraries and other binaries to use a different set of libraries. The
  77. libraries could differ in architecture, compiler options, or other
  78. optimizations.
  79. There are several examples in the ``meta-skeleton`` layer found in the
  80. :term:`Source Directory`:
  81. - :oe_git:`conf/multilib-example.conf </openembedded-core/tree/meta-skeleton/conf/multilib-example.conf>`
  82. configuration file.
  83. - :oe_git:`conf/multilib-example2.conf </openembedded-core/tree/meta-skeleton/conf/multilib-example2.conf>`
  84. configuration file.
  85. - :oe_git:`recipes-multilib/images/core-image-multilib-example.bb </openembedded-core/tree/meta-skeleton/recipes-multilib/images/core-image-multilib-example.bb>`
  86. recipe
  87. Preparing to Use Multilib
  88. -------------------------
  89. User-specific requirements drive the Multilib feature. Consequently,
  90. there is no one "out-of-the-box" configuration that would
  91. meet your needs.
  92. In order to enable Multilib, you first need to ensure your recipe is
  93. extended to support multiple libraries. Many standard recipes are
  94. already extended and support multiple libraries. You can check in the
  95. ``meta/conf/multilib.conf`` configuration file in the
  96. :term:`Source Directory` to see how this is
  97. done using the
  98. :term:`BBCLASSEXTEND` variable.
  99. Eventually, all recipes will be covered and this list will not be
  100. needed.
  101. For the most part, the :ref:`Multilib <ref-classes-multilib*>`
  102. class extension works automatically to
  103. extend the package name from ``${PN}`` to ``${MLPREFIX}${PN}``, where
  104. :term:`MLPREFIX` is the particular multilib (e.g. "lib32-" or "lib64-").
  105. Standard variables such as
  106. :term:`DEPENDS`,
  107. :term:`RDEPENDS`,
  108. :term:`RPROVIDES`,
  109. :term:`RRECOMMENDS`,
  110. :term:`PACKAGES`, and
  111. :term:`PACKAGES_DYNAMIC` are
  112. automatically extended by the system. If you are extending any manual
  113. code in the recipe, you can use the ``${MLPREFIX}`` variable to ensure
  114. those names are extended correctly.
  115. Using Multilib
  116. --------------
  117. After you have set up the recipes, you need to define the actual
  118. combination of multiple libraries you want to build. You accomplish this
  119. through your ``local.conf`` configuration file in the
  120. :term:`Build Directory`. An example configuration would be as follows::
  121. MACHINE = "qemux86-64"
  122. require conf/multilib.conf
  123. MULTILIBS = "multilib:lib32"
  124. DEFAULTTUNE:virtclass-multilib-lib32 = "x86"
  125. IMAGE_INSTALL:append = " lib32-glib-2.0"
  126. This example enables an additional library named
  127. ``lib32`` alongside the normal target packages. When combining these
  128. "lib32" alternatives, the example uses "x86" for tuning. For information
  129. on this particular tuning, see
  130. ``meta/conf/machine/include/ia32/arch-ia32.inc``.
  131. The example then includes ``lib32-glib-2.0`` in all the images, which
  132. illustrates one method of including a multiple library dependency. You
  133. can use a normal image build to include this dependency, for example::
  134. $ bitbake core-image-sato
  135. You can also build Multilib packages
  136. specifically with a command like this::
  137. $ bitbake lib32-glib-2.0
  138. Additional Implementation Details
  139. ---------------------------------
  140. There are generic implementation details as well as details that are specific to
  141. package management systems. Here are implementation details
  142. that exist regardless of the package management system:
  143. - The typical convention used for the class extension code as used by
  144. Multilib assumes that all package names specified in
  145. :term:`PACKAGES` that contain
  146. ``${PN}`` have ``${PN}`` at the start of the name. When that
  147. convention is not followed and ``${PN}`` appears at the middle or the
  148. end of a name, problems occur.
  149. - The :term:`TARGET_VENDOR`
  150. value under Multilib will be extended to "-vendormlmultilib" (e.g.
  151. "-pokymllib32" for a "lib32" Multilib with Poky). The reason for this
  152. slightly unwieldy contraction is that any "-" characters in the
  153. vendor string presently break Autoconf's ``config.sub``, and other
  154. separators are problematic for different reasons.
  155. Here are the implementation details for the RPM Package Management System:
  156. - A unique architecture is defined for the Multilib packages, along
  157. with creating a unique deploy folder under ``tmp/deploy/rpm`` in the
  158. :term:`Build Directory`. For example, consider ``lib32`` in a
  159. ``qemux86-64`` image. The possible architectures in the system are "all",
  160. "qemux86_64", "lib32:qemux86_64", and "lib32:x86".
  161. - The ``${MLPREFIX}`` variable is stripped from ``${PN}`` during RPM
  162. packaging. The naming for a normal RPM package and a Multilib RPM
  163. package in a ``qemux86-64`` system resolves to something similar to
  164. ``bash-4.1-r2.x86_64.rpm`` and ``bash-4.1.r2.lib32_x86.rpm``,
  165. respectively.
  166. - When installing a Multilib image, the RPM backend first installs the
  167. base image and then installs the Multilib libraries.
  168. - The build system relies on RPM to resolve the identical files in the
  169. two (or more) Multilib packages.
  170. Here are the implementation details for the IPK Package Management System:
  171. - The ``${MLPREFIX}`` is not stripped from ``${PN}`` during IPK
  172. packaging. The naming for a normal RPM package and a Multilib IPK
  173. package in a ``qemux86-64`` system resolves to something like
  174. ``bash_4.1-r2.x86_64.ipk`` and ``lib32-bash_4.1-rw:x86.ipk``,
  175. respectively.
  176. - The IPK deploy folder is not modified with ``${MLPREFIX}`` because
  177. packages with and without the Multilib feature can exist in the same
  178. folder due to the ``${PN}`` differences.
  179. - IPK defines a sanity check for Multilib installation using certain
  180. rules for file comparison, overridden, etc.
  181. Installing Multiple Versions of the Same Library
  182. ================================================
  183. There are be situations where you need to install and use multiple versions
  184. of the same library on the same system at the same time. This
  185. almost always happens when a library API changes and you have
  186. multiple pieces of software that depend on the separate versions of the
  187. library. To accommodate these situations, you can install multiple
  188. versions of the same library in parallel on the same system.
  189. The process is straightforward as long as the libraries use proper
  190. versioning. With properly versioned libraries, all you need to do to
  191. individually specify the libraries is create separate, appropriately
  192. named recipes where the :term:`PN` part of
  193. the name includes a portion that differentiates each library version
  194. (e.g. the major part of the version number). Thus, instead of having a
  195. single recipe that loads one version of a library (e.g. ``clutter``),
  196. you provide multiple recipes that result in different versions of the
  197. libraries you want. As an example, the following two recipes would allow
  198. the two separate versions of the ``clutter`` library to co-exist on the
  199. same system:
  200. .. code-block:: none
  201. clutter-1.6_1.6.20.bb
  202. clutter-1.8_1.8.4.bb
  203. Additionally, if
  204. you have other recipes that depend on a given library, you need to use
  205. the :term:`DEPENDS` variable to
  206. create the dependency. Continuing with the same example, if you want to
  207. have a recipe depend on the 1.8 version of the ``clutter`` library, use
  208. the following in your recipe::
  209. DEPENDS = "clutter-1.8"