blob: efb49d32d65ddc04d3c7b11f84b5b5a51d61af95 [file] [log] [blame]
Philip Liarda3802a32011-02-22 08:04:03 +00001C++ version of the libphonenumber project.
Philip Liarda3802a32011-02-22 08:04:03 +00002
3This is a port of the Java version.
4
5This project uses some third-party code:
Philippe Liardae165b12011-11-30 10:42:30 +00006 - src/phonenumbers/utf/ sources come from lib9 which is also used in Go.
Philip Liarda3802a32011-02-22 08:04:03 +00007
Philippe Liardb9a0d782011-12-07 14:52:33 +00008
9Building the library on GNU/Linux
10---------------------------------
Philip Liarda3802a32011-02-22 08:04:03 +000011Requirements:
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
David Beaumont1b31d8e2012-07-19 13:31:07 +000018 Additionally it is recommended you install the ccmake configuration tool:
19 $ sudo apt-get install cmake-curses-gui
20
Philip Liardff0ef172011-03-04 08:43:24 +000021 - Protocol Buffers
22 http://code.google.com/p/protobuf/
Shaopeng Jia4628c702011-03-24 09:10:31 +000023 Version 2.4 or more recent is required.
Philip Liardff0ef172011-03-04 08:43:24 +000024
25 You can install it very easily on a Debian-based GNU/Linux distribution:
26 $ sudo apt-get install libprotobuf-dev
27
Shaopeng Jia4628c702011-03-24 09:10:31 +000028 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
Philip Liardff0ef172011-03-04 08:43:24 +000034 - 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
Philip Liarda3802a32011-02-22 08:04:03 +000040 - 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
Philip Liard8e7e1b92011-03-03 14:35:27 +000061 - ICU
David Beaumont1b31d8e2012-07-19 13:31:07 +000062 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:
Philip Liard69921332011-06-06 08:15:16 +000084 $ cd icu/source
85 $ ./configure && make && sudo make install
Philip Liard8e7e1b92011-03-03 14:35:27 +000086
Philip Liard486cbd92011-06-07 14:41:10 +000087 - 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.
Philip Liarda3802a32011-02-22 08:04:03 +000094
95How to build libphonenumber C++:
David Beaumont1b31d8e2012-07-19 13:31:07 +000096 $ cd libphonenumber/cpp
Philip Liarda3802a32011-02-22 08:04:03 +000097 $ mkdir build
98 $ cd build
Philippe Liard7b30af62011-09-21 17:43:54 +000099 $ cmake ..
Philip Liarda3802a32011-02-22 08:04:03 +0000100 $ make
Philip Liardb36c48f2011-05-09 15:04:24 +0000101
David Beaumont1b31d8e2012-07-19 13:31:07 +0000102Troubleshooting 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
Philippe Liardb9a0d782011-12-07 14:52:33 +0000164
165Building the library on Windows (Visual Studio)
166-----------------------------------------------
167The library was tested with Visual Studio 2010.
168
169You 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
192Then run cmake-gui and specify the path to the libphonenumber's cpp directory
193and its build directory which must be created (e.g. cpp/build).
194
195When clicking on "Configure", specify the appropriate Visual Studio version
196(tested with 2010).
197
198Then CMake will need your help to locate the dependencies. You will have to set
199the following variables (this example assumes that you extracted the
200dependencies to C:/).
201
202GTEST_INCLUDE_DIR C:/gtest-1.6.0/include
203GTEST_LIB C:/gtest-1.6.0/msvc/gtest-md/Release/gtest.lib
204
205ICU_I18N_INCLUDE_DIR C:/icu/include
206ICU_I18N_LIB C:/icu/lib/icuin.lib
207
208ICU_UC_INCLUDE_DIR C:/icu/include
209ICU_UC_LIB C:/icu/lib/icuuc.lib
210
211PROTOBUF_INCLUDE_DIR C:/protobuf-2.4.1/src
212PROTOBUF_LIB C:/protobuf-2.4.1/vsprojects/Release/libprotobuf.lib
213PROTOC_BIN C:/protobuf-2.4.1/vsprojects/Release/protoc.exe
214
215Then you can click on "Configure" again. CMake should have located all the
216dependencies.
217Then click on "Generate" to generate the appropriate Visual Studio project.
218Then open cpp/build/libphonenumber.sln with Visual Studio and build the INSTALL
219target.
220
221As a result the library's headers and binaries should have been installed to
222C:/Program Files/libphonenumber/.
223Note that this path can be set by overriding the CMAKE_INSTALL_PREFIX variable
224with cmake-gui.
225
226Supported build parameters
227--------------------------
Philip Liardb36c48f2011-05-09 15:04:24 +0000228 Build parameters can be specified invoking CMake with '-DKEY=VALUE' or using a
229 CMake user interface (ccmake or cmake-gui).
230
Philippe Liard7b30af62011-09-21 17:43:54 +0000231 USE_ICU_REGEXP = ON | OFF [ON] -- Use ICU regexp engine.
Philip Liardb36c48f2011-05-09 15:04:24 +0000232 USE_LITE_METADATA = ON | OFF [OFF] -- Generates smaller metadata that doesn't
233 include example numbers.
Philippe Liard7b30af62011-09-21 17:43:54 +0000234 USE_RE2 = ON | OFF [OFF] -- Use RE2.
235 USE_STD_MAP = ON | OFF [OFF] -- Force the use of std::map.