Updated README: Added trouble shooting instructions for library issues and improved...
[platform/upstream/libphonenumber.git] / cpp / README
1 C++ version of the libphonenumber project.
2
3 This is a port of the Java version.
4
5 This project uses some third-party code:
6   - src/phonenumbers/utf/ sources come from lib9 which is also used in Go.
7
8
9 Building the library on GNU/Linux
10 ---------------------------------
11 Requirements:
12   - CMake build system
13     http://www.cmake.org
14
15     You can install it very easily on a Debian-based GNU/Linux distribution:
16     $ sudo apt-get install cmake
17
18     Additionally it is recommended you install the ccmake configuration tool:
19     $ sudo apt-get install cmake-curses-gui
20
21   - Protocol Buffers
22     http://code.google.com/p/protobuf/
23     Version 2.4 or more recent is required.
24
25     You can install it very easily on a Debian-based GNU/Linux distribution:
26     $ sudo apt-get install libprotobuf-dev
27
28     Note: if your GNU/Linux distribution doesn't provide the needed package,
29           please download and install it manually:
30     $ tar xjf protobuf-2.4.tar.bz2
31     $ cd protobuf-2.4
32     $ ./configure && make && sudo make install
33
34   - Google Test
35     http://code.google.com/p/googletest/
36
37     You can install it very easily on a Debian-based GNU/Linux distribution:
38     $ sudo apt-get install libgtest-dev
39
40   - RE2
41     http://code.google.com/p/re2/
42
43     You can install it very easily on Ubuntu Maverick and later:
44     $ sudo apt-get install libre2-dev
45
46     Otherwise if you use a Debian-based distribution you can fetch the Ubuntu
47     package which should work:
48     http://packages.ubuntu.com/maverick/libre2-dev
49
50     If you want to install it manually:
51     You need Mercurial to checkout its source code:
52     $ sudo apt-get install mercurial
53
54     Then checkout, build and install it:
55     $ hg clone https://re2.googlecode.com/hg re2
56     $ cd re2
57     $ make test
58     $ make install
59     $ make testinstall
60
61   - ICU
62     Version 4.4 or more recent is required. It can be installed easily on Debian
63     systems or be built from the most recent sources (currently 49.1.2).
64
65     If you have a Debian-based distribution you can check which version of the
66     ICU libraries is available by doing:
67     $ apt-cache show libicu-dev
68     And looking for the "Version:" string.
69
70     If this is above 4.4 then you can just do:
71     $ sudo apt-get install libicu-dev
72
73     Otherwise you need to download the source tarball for the latest version
74     from:
75       http://site.icu-project.org/download
76     And then extract it via:
77     $ tar xzf icu4c-49_1_2-src.tgz
78
79     Alternatively you can export the SVN repository to the current directory
80     via:
81     $ svn export http://source.icu-project.org/repos/icu/icu/tags/release-49-1-2/
82
83     Having acquired the latest sources, make and install it via:
84     $ cd icu/source
85     $ ./configure && make && sudo make install
86
87   - Boost
88     Version 1.40 or more recent is required.
89
90     You can install it very easily on a Debian-based GNU/Linux distribution:
91     $ sudo apt-get install libboost1.40-dev libboost-thread1.40-dev
92
93     Note: Boost Thread is the only library needed at link time.
94
95 How to build libphonenumber C++:
96   $ cd libphonenumber/cpp
97   $ mkdir build
98   $ cd build
99   $ cmake ..
100   $ make
101
102 Troubleshooting CMake via ccmake:
103   Follow these instructions if the build steps above don't work for you.
104
105   - Incorrect protocol buffer library issues
106     If the build process complains that the version of protoc being used is too
107     old or that it cannot find the correct libprotobuf library, you may need to
108     change the library path of the project.
109
110     This issue should typically only occur in cases where you have two (or more)
111     versions of the protocol buffer libraries installed on your system. This
112     step assumes that you have already manually downloaded and installed the
113     protocol buffer libraries into /usr/local (as described above).
114
115     To make cmake use the manually installed version of the protocol buffer
116     libraries, install cmake-curses-gui and use ccmake as follows.
117
118     From within libphonenumber/cpp/build:
119     $ ccmake .
120
121     You should set the following values:
122       PROTOBUF_INCLUDE_DIR         /usr/local/include
123       PROTOBUF_LIB                 /usr/local/lib/libprotobuf.so
124       PROTOC_BIN                   /usr/local/bin/protoc
125
126     Now press 'c' then 'g' to configure the new parameters and exit ccmake.
127     Finally regenerate the make files and rebuild via:
128     $ cmake ..
129     $ make
130
131   - Protoc binary not executing properly
132     If you still have issues with the protoc binary tool in /usr/local/bin not
133     running correctly (cannot find libprotobuf.so.x) then you may need to
134     configure the LD_LIBRARY_PATH. To do this, as a superuser, add the following
135     file:
136       /etc/ld.so.conf.d/libprotobuf.conf
137
138     with the contents:
139       # Use the manually installed version of the protocol buffer libraries.
140       /usr/local/lib
141
142     And then run:
143       $ sudo chmod 644 /etc/ld.so.conf.d/libprotobuf.conf
144       $ sudo ldconfig
145
146   - Incorrect ICU library issues
147     Similar to the protocol buffer library issue above, it is possible that your
148     build may fail if you have two conflicting versions of the ICU libraries
149     installed on your system. This step assumes that you have already manually
150     downloaded and installed a recent version of the ICU libraries into
151     /usr/local.
152
153     Install and run the ccmake tool (as described above) and set the following
154     values:
155       ICU_I18N_INCLUDE_DIR         /usr/local/include
156       ICU_I18N_LIB                 /usr/local/lib/libicui18n.so
157       ICU_UC_INCLUDE_DIR           /usr/local/include
158       ICU_UC_LIB                   /usr/local/lib/libicuuc.so
159
160     Now press 'c' then 'g' to configure the new parameters and exit ccmake.
161     Finally regenerate the make files and rebuild via:
162     $ cmake ..
163     $ make
164
165 Building the library on Windows (Visual Studio)
166 -----------------------------------------------
167 The library was tested with Visual Studio 2010.
168
169 You will need to manually fetch and install the following dependencies:
170   - CMake (tested with v2.8.6):
171     http://cmake.org/cmake/resources/software.html
172     * Download and install the Win32 installer.
173
174   - Boost (tested with v1.44) from BoostPro:
175     http://www.boostpro.com/download/
176     * Select all the variants and Boost DateTime and Boost Thread during the
177       installation process.
178
179   - GTest (tested with v1.6.0):
180     http://code.google.com/p/googletest/downloads/list
181     * Open msvc/gtest-md.sln with Visual Studio and build the whole solution.
182
183   - ICU (MSVC binaries, tested with v4.8.1):
184     http://site.icu-project.org/download/48#ICU4C-Download
185     * Simply extract the archive.
186
187   - Protocol Buffers:
188     http://code.google.com/p/protobuf/downloads/list
189     * Open vsprojects/protobuf.sln with Visual Studio and build the whole
190       solution.
191
192 Then run cmake-gui and specify the path to the libphonenumber's cpp directory
193 and its build directory which must be created (e.g. cpp/build).
194
195 When clicking on "Configure", specify the appropriate Visual Studio version
196 (tested with 2010).
197
198 Then CMake will need your help to locate the dependencies. You will have to set
199 the following variables (this example assumes that you extracted the
200 dependencies to C:/).
201
202 GTEST_INCLUDE_DIR         C:/gtest-1.6.0/include
203 GTEST_LIB                 C:/gtest-1.6.0/msvc/gtest-md/Release/gtest.lib
204
205 ICU_I18N_INCLUDE_DIR      C:/icu/include
206 ICU_I18N_LIB              C:/icu/lib/icuin.lib
207
208 ICU_UC_INCLUDE_DIR        C:/icu/include
209 ICU_UC_LIB                C:/icu/lib/icuuc.lib
210
211 PROTOBUF_INCLUDE_DIR      C:/protobuf-2.4.1/src
212 PROTOBUF_LIB              C:/protobuf-2.4.1/vsprojects/Release/libprotobuf.lib
213 PROTOC_BIN                C:/protobuf-2.4.1/vsprojects/Release/protoc.exe
214
215 Then you can click on "Configure" again. CMake should have located all the
216 dependencies.
217 Then click on "Generate" to generate the appropriate Visual Studio project.
218 Then open cpp/build/libphonenumber.sln with Visual Studio and build the INSTALL
219 target.
220
221 As a result the library's headers and binaries should have been installed to
222 C:/Program Files/libphonenumber/.
223 Note that this path can be set by overriding the CMAKE_INSTALL_PREFIX variable
224 with cmake-gui.
225
226 Supported build parameters
227 --------------------------
228   Build parameters can be specified invoking CMake with '-DKEY=VALUE' or using a
229   CMake user interface (ccmake or cmake-gui).
230
231   USE_ICU_REGEXP    = ON | OFF [ON]  -- Use ICU regexp engine.
232   USE_LITE_METADATA = ON | OFF [OFF] -- Generates smaller metadata that doesn't
233                                         include example numbers.
234   USE_RE2           = ON | OFF [OFF] -- Use RE2.
235   USE_STD_MAP       = ON | OFF [OFF] -- Force the use of std::map.