1--- 2layout: default 3title: Packaging ICU4C 4nav_order: 3 5parent: ICU4C 6--- 7<!-- 8© 2020 and later: Unicode, Inc. and others. 9License & terms of use: http://www.unicode.org/copyright.html 10--> 11 12# Packaging ICU4C 13{: .no_toc } 14 15## Contents 16{: .no_toc .text-delta } 17 181. TOC 19{:toc} 20 21--- 22 23## Overview 24 25This chapter describes, for the advanced user, how to package ICU4C for 26distribution, whether alone, as part of an application, or as part of the 27operating system. 28 29There are many ways that a person can package ICU with their software products. Usually only the libraries need to be considered for packaging. 30 31On UNIX, you should use `gmake install` to make it easier to develop and package ICU. The bin, lib and include directories are needed to develop applications that use ICU. These directories will be created relative to the `--prefix=`dir" configure option (See the [UNIX build instructions](#how-to-build-and-install-on-unix)). When ICU is built on Windows, a similar directory structure is built. 32 33When changes have been made to the standard ICU distribution, it is recommended that at least one of the following guidelines be followed for special packaging. 34 351. Add a suffix name to the library names. This can be done with the `--with-library-suffix` configure option. 362. The installation script should install the ICU libraries into the application's directory. 37 38Following these guidelines prevents other applications that use a standard ICU 39distribution from conflicting with any libraries that you need. On operating systems 40that do not have a standard C++ ABI (name mangling) for compilers, it is recommended to 41do this special packaging anyway. More details on customizing ICU are available in the 42[User Guide](../). 43The [ICU Source Code Organization](./index/#icu-source-code-organization) section of 44the ICU4C gives a more complete description of the libraries. 45 46ICU has several libraries for you to use. Here is an example of libraries that are frequently packaged. 47 48| Library Name | Windows Filename | Linux Filename | Comment | 49|-------------------------------------|------------------|------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 50| Data Library | icudtXYl.dll | libicudata.so.XY.Z | Data required by the Common and I18n libraries. There are many ways to package and [customize this data](../icu_data), but by default this is all you need. | 51| Common Library | icuucXY.dll | libicuuc.so.XY.Z | Base library required by all other ICU libraries. | 52| Internationalization (i18n) Library | icuinXY.dll | libicui18n.so.XY.Z | A library that contains many locale based internationalization (i18n) functions. | 53| Layout Extensions Engine | iculxXY.dll | libiculx.so.XY.Z | An optional engine for doing paragraph layout that uses parts of ICU. HarfBuzz is required. | 54| ICU I/O (Unicode stdio) Library | icuioXY.dll | libicuio.so.XY.Z | An optional library that provides a stdio like API with Unicode support. | 55| Tool Utility Library | icutuXY.dll | libicutu.so.XY.Z | An internal library that contains internal APIs that are only used by ICU's tools. If you do not use ICU's tools, you do not need this library. | 56 57 58Normally only the above ICU libraries need to be considered for packaging. The versionless symbolic links to these libraries are only needed for easier development. The _X_, _Y_ and _Z_ parts of the name are the version numbers of ICU. For example, ICU 2.0.2 would have the name libicuuc.so.20.2 for the common library. The exact format of the library names can vary between platforms due to how each platform can handles library versioning. 59 60## Making ICU Smaller 61 62The ICU project is intended to provide everything an application might need in 63order to process Unicode. However, in doing so, the results may become quite 64large on disk. A default build of ICU normally results in over 16 MB of data, 65and a substantial amount of object code. This section describes some techniques 66to reduce the size of ICU to only the items which are required for your 67application. 68 69### Link to ICU statically 70 71If you add the `--enable-static` option to the ICU command line build (Makefile 72or cygwin), ICU will also build a static library version which you can link to 73only the exact functions your application needs. Users of your ICU must compile 74with -DU_STATIC_IMPLEMENTATION. Also see [How To Use ICU](../icu/howtouseicu.md). 75 76### Reduce the number of libraries used 77 78ICU consists of a number of different libraries. The library dependency chart in the [Design](../design#library-dependencies-c) 79chapter can be used to understand and 80determine the exact set of libraries needed. 81 82### Disable ICU features 83 84Certain features of ICU may be turned on and off through preprocessor defines. 85These switches are located in the file "uconfig.h", and disable the code for 86certain features from being built. 87 88All of these switches are defined to '0' by default, unless overridden by the 89build environment, or by modifying uconfig.h itself. 90 91| Switch Name | Library | Effect if #defined to '1' | 92|--------------------------------|------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------| 93| UCONFIG_ONLY_COLLATION | common & i18n | Turn off all other modules named here except collation and legacy conversion | 94| UCONFIG_NO_LEGACY_CONVERSION | common | Turn off conversion apart from UTF, CESU-8, SCSU, BOCU-1, US-ASCII, and ISO-8859-1. Not possible to turn off legacy conversion on EBCDIC platforms. | 95| UCONFIG_NO_BREAK_ITERATION | common | Turn off break iteration | 96| UCONFIG_NO_COLLATION | i18n | Turn off collation and collation-based string search. | 97| UCONFIG_NO_FORMATTING | i18n | Turn off all formatting (date, time, number, etc), and calendar/timezone services. | 98| UCONFIG_NO_TRANSLITERATION | i18n | Turn off script-to-script transliteration | 99| UCONFIG_NO_REGULAR_EXPRESSIONS | i18n | Turn off the regular expression functionality | 100 101> :point_right: **NOTE**: *These switches do not necessarily disable data generation. For example, disabling formatting does not prevent formatting data from being built into the resource bundles. See the section on ICU data, for information on changing data packaging.* 102*However, some ICU data builders will not function with these switches set, such 103as UCONFIG_NO_FILE_IO or UCONFIG_NO_REGULAR_EXPRESSIONS. If using these 104switches, it is best to use pre-built ICU data, such as is the default for ICU 105source downloads, as opposed to data builds "from scratch" out of SVN.* 106 107#### Using UCONFIG switches with Environment Variables 108 109This method involves setting an environment variable when ICU is built. For 110example, on a POSIX-like platform, settings may be chosen at the point 111runConfigureICU is run: 112 113```shell 114env CPPFLAGS="-DUCONFIG_NO_COLLATION=1 -DUCONFIGU_NO_FORMATTING=1" \ 115 runConfigureICU SOLARISCC ... 116``` 117 118> :point_right: **Note**: When end-user code is compiled, 119> it must also have the same CPPFLAGS 120> set, or else calling some functions may result in a link failure. 121 122#### Using UCONFIG switches by changing uconfig.h 123 124This method involves modifying the source file 125icu/source/common/unicode/uconfig.h directly, before ICU is built. It has the 126advantage that the configuration change is propagated to all clients who compile 127against this build of ICU, however the altered file must be tracked when the 128next version of ICU is installed. 129 130Modify 'uconfig.h' to add the following lines before the first #ifndef 131UCONFIG_... section 132 133```c 134#ifndef UCONFIG_NO_COLLATION 135#define UCONFIG_NO_COLLATION 1 136#enddif 137#ifndef UCONFIG_NO_FORMATTING 138#define UCONFIG_NO_FORMATTING 1 139#endif 140``` 141 142### Reduce ICU Data used 143 144There are many ways in which ICU data may be reduced. If only certain locales or 145converters will be used, others may be removed. Additionally, data may be 146packaged as individual files or interchangeable archives (.dat files), allowing 147data to be installed and removed without rebuilding ICU. For details, see the 148[ICU Data](../icudata.md) chapter. 149 150## ICU Versions 151 152(This section assumes the reader is familiar with [ICU version numbers](../design#version-numbers-in-icu) as 153covered in the [Design](../design.md) chapter, and filename conventions for 154libraries as described above.) 155 156### POSIX Library Names 157 158The following table gives an example of the dynamically linked library and 159symbolic links built by ICU for the common ('uc') library, version 5.4.3, for 160Linux 161 162| File | Links to | Purpose | 163|------------------|------------------|------------------------------------------------------------------------------------| 164| `libicuuc.so` | `libicuuc.so.54.3` | Required for link: Applications compiled with ' -licuuc' will follow this symlink. | 165| `libicuuc.so.54` | `libicuuc.so.54.3` | Required for runtime: This name is what applications actually link against. | 166| `libicuuc.so.54.3` | Actual library | Required for runtime and link. Contains the name `libicuuc.so.54`. | 167 168> :point_right: **Note**: This discussion gives 169> Linux as an example, but it is typical for most platforms, 170> of which AIX and 390 (zOS) are exceptions. 171 172An application compiled with '-licuuc' will follow the symlink from `libicuuc.so` 173to `libicuuc.so.54.3`, and will actually read the file `libicuuc.so.54.3`. (fully 174qualified). This library file has an embedded name (SONAME) of `libicuuc.so.54`, 175that is, with only the major and minor number. The linker will write **this** 176name into the client application, because Binary compatibility is for versions 177that share the same major+minor number. 178 179If ICU version 5.4.**7** is subsequently installed, the following files may be 180updated. 181 182| File | Links to | Purpose | 183|------------------|------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------| 184| `libicuuc.so` | `libicuuc.so.54.7` | Required for link: Newly linked applications will follow this link, which should not cause any functional difference at link time. | 185| libicuuc.so.54` | `libicuuc.so.54.7` | Required for runtime: Because it now links to version .7, existing applications linked to version 5.4.3 will follow this link and use the 5.4.7 code. | 186| `libicuuc.so.54.7` | Actual library | Required for runtime and link. Contains the name `libicuuc.so.54`. | 187 188If ICU version 5.6.3 or 3.2.9 were installed, they would not affect 189already-linked applications, because the major+minor numbers are different - 56 190and 32, respectively, as opposed to 54. They would, however, replace the link 191`libicuuc.so`, which controls which version of ICU newly-linked applications 192use. 193 194In summary, what files should an application distribute in order to include a 195functional runtime copy of ICU 5.4.3? The above application should distribute 196`libicuuc.so.54.3` and the symbolic link `libicuuc.so.54`. (If symbolic links pose 197difficulty, `libicuuc.so.54.3` may be renamed to `libicuuc.so.54`, and only 198`libicuuc.so.54` distributed. This is less informative, but functional.) 199 200### POSIX Library suffix 201 202The --with-library-suffix option may be used with runConfigureICU or configure, 203to distinguish on disk specially modified versions of ICU. For example, the 204option --with-library-suffix=**myapp** will produce libraries with names such as 205libicuuc**myapp**.so.54.3, thus preventing another ICU user from using myapp's 206custom ICU libraries. 207 208While two or more versions of ICU may be linked into the same application as 209long as the major and minor numbers are different, changing the library suffix 210is not sufficient to allow the same version of ICU to be linked. In other words, 211linking ICU 5.4.3, 5.6.3, and 3.2.9 together is allowed, but 5.4.3 and 5.4.7 may 212not be linked together, nor may 5.4.3 and 5.4.3-myapp be linked together. 213 214### Windows library names 215 216Assuming ICU version 5.4.3, Windows library names will follow this pattern: 217 218| File | Purpose | 219|---------------|--------------------------------------------------------------------------------------------| 220| `icu`**uc**`.lib` | Release Link-time library. Needed for development. Contains `icuuc54.dll` name internally. | 221| `icuuc54.dll` | Release runtime library. Needed for runtime. | 222| `icuuc`**d**`.lib` | Debug link-time library (The `d` suffix indicates debug) | 223| `icuuc54`**d**`.dll` | Debug runtime library. | 224 225Debug applications must be linked with debug libraries, and release applications 226with release libraries. 227 228When a new version of ICU is installed, the .lib files will be replaced so as to 229keep new compiles in sync with the newly installed header files, and the latest 230DLL. As well, if the new ICU version has the same major+minor version (such as 2315.4.7), then DLLs will be replaced, as they are binary compatible. However, if 232an ICU with a different major+minor version is installed, such as 5.5, then new 233DLLs will be copied with names such as 'icuuc55.dll'. 234 235## Packaging ICU4C as Part of the Operating System 236 237The services which are now known as ICU were written to provide operating 238system-level and application environment-level services. Several operating 239systems include ICU as a standard or optional package. 240See [ICU Binary Compatibility](../design#icu-binary-compatibility) for 241more details. 242