David Beaumont | 14dc215 | 2014-11-28 15:49:34 +0000 | [diff] [blame] | 1 | C++ version of the libphonenumber project |
| 2 | ========================================= |
Philip Liard | a3802a3 | 2011-02-22 08:04:03 +0000 | [diff] [blame] | 3 | |
David Beaumont | 14dc215 | 2014-11-28 15:49:34 +0000 | [diff] [blame] | 4 | This library is a port of the Java version. |
Philip Liard | a3802a3 | 2011-02-22 08:04:03 +0000 | [diff] [blame] | 5 | |
| 6 | This project uses some third-party code: |
Philippe Liard | ae165b1 | 2011-11-30 10:42:30 +0000 | [diff] [blame] | 7 | - src/phonenumbers/utf/ sources come from lib9 which is also used in Go. |
Philip Liard | a3802a3 | 2011-02-22 08:04:03 +0000 | [diff] [blame] | 8 | |
Philippe Liard | b9a0d78 | 2011-12-07 14:52:33 +0000 | [diff] [blame] | 9 | |
David Beaumont | 14dc215 | 2014-11-28 15:49:34 +0000 | [diff] [blame] | 10 | Installing the library on GNU/Linux |
| 11 | ----------------------------------- |
| 12 | In recent Debian-based distributions you may be able to simply install the |
| 13 | libphonenumber library directly. |
| 14 | |
| 15 | Installing the binary packages: |
| 16 | - Use this if you just need to use or link against the library: |
| 17 | $ sudo apt-get install libphonenumber6 libphonenumber6-dev |
| 18 | |
| 19 | Installing the source package: |
| 20 | - Use this if you wish to develop or debug the library: |
| 21 | $ sudo apt-get source libphonenumber |
| 22 | |
| 23 | The latest packages can be found on the Debian packages site: |
| 24 | https://packages.debian.org/search?searchon=names&keywords=libphonenumber |
| 25 | |
| 26 | |
| 27 | Manually installing the library on GNU/Linux |
| 28 | -------------------------------------------- |
| 29 | You should only need these instructions if the above instructions do not work. |
| 30 | |
| 31 | The example command lines below assume that you have a Debian-based GNU/Linux |
| 32 | distribution. Other distributions and packaging systems will differ. |
| 33 | |
| 34 | Quickstart: |
| 35 | - In recent Debian-based distributions, it should be sufficent to run: |
| 36 | $ sudo apt-get install \ |
| 37 | cmake cmake-curses-gui libprotobuf-dev libgtest-dev libre2-dev \ |
Keghani Kouzoujian | 5415fca | 2016-04-01 10:30:00 +0200 | [diff] [blame] | 38 | libicu-dev libboost-dev libboost-thread-dev libboost-system-dev \ |
| 39 | protobuf-compiler |
David Beaumont | 14dc215 | 2014-11-28 15:49:34 +0000 | [diff] [blame] | 40 | |
| 41 | If any of these packages fails to install correctly, follow the instructions |
| 42 | in the appropriate section below. |
| 43 | |
Philip Liard | a3802a3 | 2011-02-22 08:04:03 +0000 | [diff] [blame] | 44 | Requirements: |
| 45 | - CMake build system |
| 46 | http://www.cmake.org |
| 47 | |
David Beaumont | 14dc215 | 2014-11-28 15:49:34 +0000 | [diff] [blame] | 48 | Installation: |
Philip Liard | a3802a3 | 2011-02-22 08:04:03 +0000 | [diff] [blame] | 49 | $ sudo apt-get install cmake |
| 50 | |
David Beaumont | 1b31d8e | 2012-07-19 13:31:07 +0000 | [diff] [blame] | 51 | Additionally it is recommended you install the ccmake configuration tool: |
| 52 | $ sudo apt-get install cmake-curses-gui |
| 53 | |
Philip Liard | ff0ef17 | 2011-03-04 08:43:24 +0000 | [diff] [blame] | 54 | - Protocol Buffers |
| 55 | http://code.google.com/p/protobuf/ |
David Beaumont | 14dc215 | 2014-11-28 15:49:34 +0000 | [diff] [blame] | 56 | Version 2.4 or more recent is required (this is available by default for |
| 57 | recent Debian-based GNU/Linux distributions). |
Philip Liard | ff0ef17 | 2011-03-04 08:43:24 +0000 | [diff] [blame] | 58 | |
David Beaumont | 14dc215 | 2014-11-28 15:49:34 +0000 | [diff] [blame] | 59 | You can check which version is available: |
Keghani Kouzoujian | 40f3fe0 | 2016-03-31 16:06:54 +0200 | [diff] [blame] | 60 | $ apt-cache show libprotobuf-dev |
David Beaumont | 14dc215 | 2014-11-28 15:49:34 +0000 | [diff] [blame] | 61 | Package: libprotobuf-dev |
| 62 | Source: protobuf |
| 63 | Version: 2.5.0-9ubuntu1 <-- This must be >= 2.4.0 |
| 64 | ... |
| 65 | |
| 66 | Installation: |
Philip Liard | ff0ef17 | 2011-03-04 08:43:24 +0000 | [diff] [blame] | 67 | $ sudo apt-get install libprotobuf-dev |
| 68 | |
Shaopeng Jia | 4628c70 | 2011-03-24 09:10:31 +0000 | [diff] [blame] | 69 | Note: if your GNU/Linux distribution doesn't provide the needed package, |
| 70 | please download and install it manually: |
| 71 | $ tar xjf protobuf-2.4.tar.bz2 |
| 72 | $ cd protobuf-2.4 |
| 73 | $ ./configure && make && sudo make install |
| 74 | |
Philip Liard | ff0ef17 | 2011-03-04 08:43:24 +0000 | [diff] [blame] | 75 | - Google Test |
| 76 | http://code.google.com/p/googletest/ |
| 77 | |
David Beaumont | 14dc215 | 2014-11-28 15:49:34 +0000 | [diff] [blame] | 78 | Installation: |
Philip Liard | ff0ef17 | 2011-03-04 08:43:24 +0000 | [diff] [blame] | 79 | $ sudo apt-get install libgtest-dev |
| 80 | |
Philip Liard | a3802a3 | 2011-02-22 08:04:03 +0000 | [diff] [blame] | 81 | - RE2 |
| 82 | http://code.google.com/p/re2/ |
| 83 | |
David Beaumont | 14dc215 | 2014-11-28 15:49:34 +0000 | [diff] [blame] | 84 | Installation: |
Philip Liard | a3802a3 | 2011-02-22 08:04:03 +0000 | [diff] [blame] | 85 | $ sudo apt-get install libre2-dev |
| 86 | |
David Beaumont | 14dc215 | 2014-11-28 15:49:34 +0000 | [diff] [blame] | 87 | Note that some distributions (notably Ubuntu 10.4) may not include this, |
| 88 | so you might need to download and install it manually. |
Philip Liard | a3802a3 | 2011-02-22 08:04:03 +0000 | [diff] [blame] | 89 | |
David Beaumont | 14dc215 | 2014-11-28 15:49:34 +0000 | [diff] [blame] | 90 | Find and download the Debian packages for your system. For example: |
| 91 | http://packages.ubuntu.com/utopic/libre2-1 |
| 92 | http://packages.ubuntu.com/utopic/libre2-dev |
Philip Liard | a3802a3 | 2011-02-22 08:04:03 +0000 | [diff] [blame] | 93 | |
David Beaumont | 14dc215 | 2014-11-28 15:49:34 +0000 | [diff] [blame] | 94 | You need to download both the libre2-dev and libre2-1 packages. |
| 95 | Once downloaded, install them with: |
| 96 | $ sudo dpkg -i libre2*.deb |
| 97 | |
| 98 | If you want to install it from source, it's available via Mercurial at: |
| 99 | https://re2.googlecode.com/hg |
| 100 | however precise instructions on building and installing are outside the |
| 101 | scope of this document. |
Philip Liard | a3802a3 | 2011-02-22 08:04:03 +0000 | [diff] [blame] | 102 | |
Philip Liard | 8e7e1b9 | 2011-03-03 14:35:27 +0000 | [diff] [blame] | 103 | - ICU |
David Beaumont | 14dc215 | 2014-11-28 15:49:34 +0000 | [diff] [blame] | 104 | Installation: |
David Beaumont | 1b31d8e | 2012-07-19 13:31:07 +0000 | [diff] [blame] | 105 | $ sudo apt-get install libicu-dev |
| 106 | |
| 107 | Otherwise you need to download the source tarball for the latest version |
| 108 | from: |
| 109 | http://site.icu-project.org/download |
| 110 | And then extract it via: |
David Beaumont | 14dc215 | 2014-11-28 15:49:34 +0000 | [diff] [blame] | 111 | $ tar xzf icu4c-*-src.tgz |
David Beaumont | 1b31d8e | 2012-07-19 13:31:07 +0000 | [diff] [blame] | 112 | |
| 113 | Alternatively you can export the SVN repository to the current directory |
| 114 | via: |
David Beaumont | 14dc215 | 2014-11-28 15:49:34 +0000 | [diff] [blame] | 115 | $ svn export http://source.icu-project.org/repos/icu/icu/tags/release-XX-y-z/ |
David Beaumont | 1b31d8e | 2012-07-19 13:31:07 +0000 | [diff] [blame] | 116 | |
| 117 | Having acquired the latest sources, make and install it via: |
Philip Liard | 6992133 | 2011-06-06 08:15:16 +0000 | [diff] [blame] | 118 | $ cd icu/source |
| 119 | $ ./configure && make && sudo make install |
Philip Liard | 8e7e1b9 | 2011-03-03 14:35:27 +0000 | [diff] [blame] | 120 | |
Philip Liard | 486cbd9 | 2011-06-07 14:41:10 +0000 | [diff] [blame] | 121 | - Boost |
Philippe Liard | 9f0d77e | 2013-04-30 12:08:05 +0000 | [diff] [blame] | 122 | Version 1.40 or more recent is required if you need libphonenumber to be |
| 123 | thread-safe. If you access libphonenumber from a single thread, you can |
| 124 | avoid the Boost dependency by disabling the USE_BOOST CMake option (see |
| 125 | Troubleshooting section below for information about ccmake). |
Philip Liard | 486cbd9 | 2011-06-07 14:41:10 +0000 | [diff] [blame] | 126 | |
| 127 | You can install it very easily on a Debian-based GNU/Linux distribution: |
David Beaumont | 14dc215 | 2014-11-28 15:49:34 +0000 | [diff] [blame] | 128 | $ sudo apt-get install libboost-dev libboost-thread-dev libboost-system-dev |
Philip Liard | 486cbd9 | 2011-06-07 14:41:10 +0000 | [diff] [blame] | 129 | |
| 130 | Note: Boost Thread is the only library needed at link time. |
Philip Liard | a3802a3 | 2011-02-22 08:04:03 +0000 | [diff] [blame] | 131 | |
David Beaumont | 14dc215 | 2014-11-28 15:49:34 +0000 | [diff] [blame] | 132 | |
David Beaumont | a34ddc9 | 2015-03-06 13:53:07 +0100 | [diff] [blame] | 133 | Building and testing the library |
| 134 | -------------------------------- |
David Beaumont | 1b31d8e | 2012-07-19 13:31:07 +0000 | [diff] [blame] | 135 | $ cd libphonenumber/cpp |
Philip Liard | a3802a3 | 2011-02-22 08:04:03 +0000 | [diff] [blame] | 136 | $ mkdir build |
| 137 | $ cd build |
Philippe Liard | 7b30af6 | 2011-09-21 17:43:54 +0000 | [diff] [blame] | 138 | $ cmake .. |
Philip Liard | a3802a3 | 2011-02-22 08:04:03 +0000 | [diff] [blame] | 139 | $ make |
David Beaumont | a34ddc9 | 2015-03-06 13:53:07 +0100 | [diff] [blame] | 140 | $ ./libphonenumber_test |
David Beaumont | 14dc215 | 2014-11-28 15:49:34 +0000 | [diff] [blame] | 141 | |
Keghani Kouzoujian | 40f3fe0 | 2016-03-31 16:06:54 +0200 | [diff] [blame] | 142 | |
| 143 | Manually installing the library on Mac |
| 144 | -------------------------------------- |
| 145 | |
| 146 | You can easily install dependencies on Mac using a package manager. In these |
| 147 | instructions we use Homebrew (http://brew.sh). |
| 148 | |
| 149 | Install Homebrew package manager and use it to install dependencies: |
| 150 | $ /usr/bin/ruby -e "$(curl -fsSL \ |
| 151 | https://raw.githubusercontent.com/Homebrew/install/master/install)" |
| 152 | $ brew install boost cmake icu4c pkg-config protobuf wget |
| 153 | |
| 154 | See https://github.com/Homebrew/homebrew/issues/14099 - homebrew does not have |
| 155 | gtest. We don't need to install gtest, we only copy sources. For example: |
| 156 | $ mkdir ~/googletest_clone |
| 157 | $ cd ~/googletest_clone |
| 158 | $ git clone https://github.com/google/googletest.git |
| 159 | |
| 160 | Get the libphonenumber source. For example: |
| 161 | $ mkdir ~/libphonenumber_clone |
| 162 | $ cd ~/libphonenumber_clone |
| 163 | $ git clone https://github.com/googlei18n/libphonenumber.git |
| 164 | |
| 165 | Build and test the library: |
| 166 | $ cd libphonenumber/cpp |
| 167 | $ mkdir build |
| 168 | $ cd build |
Keghani Kouzoujian | d90cd60 | 2016-04-01 11:19:39 +0200 | [diff] [blame] | 169 | Replace XXX in the commands below with the appropriate version number: |
Keghani Kouzoujian | 40f3fe0 | 2016-03-31 16:06:54 +0200 | [diff] [blame] | 170 | $ cmake \ |
| 171 | -DGTEST_SOURCE_DIR=~/googletest_clone/googletest/googletest/ \ |
| 172 | -DGTEST_INCLUDE_DIR=~/googletest_clone/googletest/googletest/include/ \ |
| 173 | -DICU_UC_INCLUDE_DIR=/usr/local/Cellar/icu4c/XXX/include/ \ |
| 174 | -DICU_UC_LIB=/usr/local/Cellar/icu4c/XXX/lib/libicuuc.dylib \ |
| 175 | -DICU_I18N_INCLUDE_DIR=/usr/local/Cellar/icu4c/XXX/include/ \ |
| 176 | -DICU_I18N_LIB=/usr/local/Cellar/icu4c/XXX/lib/libicui18n.dylib \ |
| 177 | -DUSE_STD_MAP=ON \ |
| 178 | .. |
| 179 | $ make |
| 180 | $ ./libphonenumber_test |
| 181 | |
| 182 | Optional: Deleting & uninstalling everything again: |
| 183 | $ cd |
| 184 | $ rm -rf ~/libphonenumber_clone ~/googletest_clone |
| 185 | |
| 186 | openssl is a dependency of wget and installed with it by Homebrew. If you had |
| 187 | openssl before installing wget don't uninstall here. |
| 188 | $ brew uninstall boost cmake icu4c openssl pkg-config protobuf wget |
| 189 | |
| 190 | $ /usr/bin/ruby -e "$(curl -fsSL \ |
| 191 | https://raw.githubusercontent.com/Homebrew/install/master/uninstall)" |
| 192 | |
| 193 | Homebrew will have changed permissions at installation. See output of previous |
| 194 | command for how to change them back, for example: |
| 195 | $ sudo chmod 0755 /usr/local |
| 196 | $ sudo chgrp wheel /usr/local |
| 197 | |
| 198 | |
David Beaumont | 14dc215 | 2014-11-28 15:49:34 +0000 | [diff] [blame] | 199 | Troubleshooting CMake via ccmake |
| 200 | -------------------------------- |
David Beaumont | 1b31d8e | 2012-07-19 13:31:07 +0000 | [diff] [blame] | 201 | Follow these instructions if the build steps above don't work for you. |
| 202 | |
| 203 | - Incorrect protocol buffer library issues |
| 204 | If the build process complains that the version of protoc being used is too |
| 205 | old or that it cannot find the correct libprotobuf library, you may need to |
| 206 | change the library path of the project. |
| 207 | |
| 208 | This issue should typically only occur in cases where you have two (or more) |
| 209 | versions of the protocol buffer libraries installed on your system. This |
| 210 | step assumes that you have already manually downloaded and installed the |
| 211 | protocol buffer libraries into /usr/local (as described above). |
| 212 | |
| 213 | To make cmake use the manually installed version of the protocol buffer |
| 214 | libraries, install cmake-curses-gui and use ccmake as follows. |
| 215 | |
| 216 | From within libphonenumber/cpp/build: |
| 217 | $ ccmake . |
| 218 | |
| 219 | You should set the following values: |
| 220 | PROTOBUF_INCLUDE_DIR /usr/local/include |
| 221 | PROTOBUF_LIB /usr/local/lib/libprotobuf.so |
| 222 | PROTOC_BIN /usr/local/bin/protoc |
| 223 | |
| 224 | Now press 'c' then 'g' to configure the new parameters and exit ccmake. |
| 225 | Finally regenerate the make files and rebuild via: |
| 226 | $ cmake .. |
| 227 | $ make |
| 228 | |
| 229 | - Protoc binary not executing properly |
| 230 | If you still have issues with the protoc binary tool in /usr/local/bin not |
| 231 | running correctly (cannot find libprotobuf.so.x) then you may need to |
| 232 | configure the LD_LIBRARY_PATH. To do this, as a superuser, add the following |
| 233 | file: |
| 234 | /etc/ld.so.conf.d/libprotobuf.conf |
| 235 | |
| 236 | with the contents: |
| 237 | # Use the manually installed version of the protocol buffer libraries. |
| 238 | /usr/local/lib |
| 239 | |
| 240 | And then run: |
| 241 | $ sudo chmod 644 /etc/ld.so.conf.d/libprotobuf.conf |
| 242 | $ sudo ldconfig |
| 243 | |
| 244 | - Incorrect ICU library issues |
| 245 | Similar to the protocol buffer library issue above, it is possible that your |
| 246 | build may fail if you have two conflicting versions of the ICU libraries |
| 247 | installed on your system. This step assumes that you have already manually |
| 248 | downloaded and installed a recent version of the ICU libraries into |
| 249 | /usr/local. |
| 250 | |
| 251 | Install and run the ccmake tool (as described above) and set the following |
| 252 | values: |
| 253 | ICU_I18N_INCLUDE_DIR /usr/local/include |
| 254 | ICU_I18N_LIB /usr/local/lib/libicui18n.so |
| 255 | ICU_UC_INCLUDE_DIR /usr/local/include |
| 256 | ICU_UC_LIB /usr/local/lib/libicuuc.so |
| 257 | |
| 258 | Now press 'c' then 'g' to configure the new parameters and exit ccmake. |
| 259 | Finally regenerate the make files and rebuild via: |
| 260 | $ cmake .. |
| 261 | $ make |
Philippe Liard | b9a0d78 | 2011-12-07 14:52:33 +0000 | [diff] [blame] | 262 | |
Keghani Kouzoujian | 40f3fe0 | 2016-03-31 16:06:54 +0200 | [diff] [blame] | 263 | |
Philippe Liard | b9a0d78 | 2011-12-07 14:52:33 +0000 | [diff] [blame] | 264 | Building the library on Windows (Visual Studio) |
| 265 | ----------------------------------------------- |
| 266 | The library was tested with Visual Studio 2010. |
| 267 | |
| 268 | You will need to manually fetch and install the following dependencies: |
| 269 | - CMake (tested with v2.8.6): |
| 270 | http://cmake.org/cmake/resources/software.html |
| 271 | * Download and install the Win32 installer. |
| 272 | |
| 273 | - Boost (tested with v1.44) from BoostPro: |
| 274 | http://www.boostpro.com/download/ |
| 275 | * Select all the variants and Boost DateTime and Boost Thread during the |
| 276 | installation process. |
Philippe Liard | 9f0d77e | 2013-04-30 12:08:05 +0000 | [diff] [blame] | 277 | See Linux instructions for information about thread-safety. |
Philippe Liard | b9a0d78 | 2011-12-07 14:52:33 +0000 | [diff] [blame] | 278 | |
| 279 | - GTest (tested with v1.6.0): |
| 280 | http://code.google.com/p/googletest/downloads/list |
| 281 | * Open msvc/gtest-md.sln with Visual Studio and build the whole solution. |
| 282 | |
| 283 | - ICU (MSVC binaries, tested with v4.8.1): |
| 284 | http://site.icu-project.org/download/48#ICU4C-Download |
| 285 | * Simply extract the archive. |
| 286 | |
| 287 | - Protocol Buffers: |
| 288 | http://code.google.com/p/protobuf/downloads/list |
| 289 | * Open vsprojects/protobuf.sln with Visual Studio and build the whole |
| 290 | solution. |
| 291 | |
| 292 | Then run cmake-gui and specify the path to the libphonenumber's cpp directory |
| 293 | and its build directory which must be created (e.g. cpp/build). |
| 294 | |
| 295 | When clicking on "Configure", specify the appropriate Visual Studio version |
| 296 | (tested with 2010). |
| 297 | |
| 298 | Then CMake will need your help to locate the dependencies. You will have to set |
| 299 | the following variables (this example assumes that you extracted the |
| 300 | dependencies to C:/). |
| 301 | |
| 302 | GTEST_INCLUDE_DIR C:/gtest-1.6.0/include |
| 303 | GTEST_LIB C:/gtest-1.6.0/msvc/gtest-md/Release/gtest.lib |
| 304 | |
| 305 | ICU_I18N_INCLUDE_DIR C:/icu/include |
| 306 | ICU_I18N_LIB C:/icu/lib/icuin.lib |
| 307 | |
| 308 | ICU_UC_INCLUDE_DIR C:/icu/include |
| 309 | ICU_UC_LIB C:/icu/lib/icuuc.lib |
| 310 | |
| 311 | PROTOBUF_INCLUDE_DIR C:/protobuf-2.4.1/src |
| 312 | PROTOBUF_LIB C:/protobuf-2.4.1/vsprojects/Release/libprotobuf.lib |
| 313 | PROTOC_BIN C:/protobuf-2.4.1/vsprojects/Release/protoc.exe |
| 314 | |
| 315 | Then you can click on "Configure" again. CMake should have located all the |
| 316 | dependencies. |
| 317 | Then click on "Generate" to generate the appropriate Visual Studio project. |
| 318 | Then open cpp/build/libphonenumber.sln with Visual Studio and build the INSTALL |
| 319 | target. |
| 320 | |
| 321 | As a result the library's headers and binaries should have been installed to |
| 322 | C:/Program Files/libphonenumber/. |
| 323 | Note that this path can be set by overriding the CMAKE_INSTALL_PREFIX variable |
| 324 | with cmake-gui. |
| 325 | |
Keghani Kouzoujian | 40f3fe0 | 2016-03-31 16:06:54 +0200 | [diff] [blame] | 326 | |
Philippe Liard | b9a0d78 | 2011-12-07 14:52:33 +0000 | [diff] [blame] | 327 | Supported build parameters |
| 328 | -------------------------- |
Philip Liard | b36c48f | 2011-05-09 15:04:24 +0000 | [diff] [blame] | 329 | Build parameters can be specified invoking CMake with '-DKEY=VALUE' or using a |
| 330 | CMake user interface (ccmake or cmake-gui). |
| 331 | |
Philippe Liard | b8a13bf | 2013-05-07 12:59:58 +0000 | [diff] [blame] | 332 | USE_ALTERNATE_FORMATS = ON | OFF [ON] -- Use alternate formats for the phone |
| 333 | number matcher. |
| 334 | USE_BOOST = ON | OFF [ON] -- Use Boost. This is only needed in |
Philippe Liard | c2f2752 | 2013-06-17 11:53:01 +0000 | [diff] [blame] | 335 | multi-threaded environments that |
| 336 | are not Linux and Mac. |
| 337 | Libphonenumber relies on Boost for |
| 338 | non-POSIX (e.g. Windows) |
| 339 | multi-threading. |
Philippe Liard | b8a13bf | 2013-05-07 12:59:58 +0000 | [diff] [blame] | 340 | USE_ICU_REGEXP = ON | OFF [ON] -- Use ICU regexp engine. |
| 341 | USE_LITE_METADATA = ON | OFF [OFF] -- Generates smaller metadata that |
| 342 | doesn't include example numbers. |
| 343 | USE_RE2 = ON | OFF [OFF] -- Use RE2. |
| 344 | USE_STD_MAP = ON | OFF [OFF] -- Force the use of std::map. |