# ICM Modbus Building Document
## Environment
* Ubuntu 20.04 64bit
* cmake 3.16
* boost C++ 1.70.0
* ICU 64.2
* GLIBCXX_3.4.26 (gcc 7)
## Building Steps
1. update gcc
2. build and install cmake
3. build and install boost C++
4. build the project
## Check gcc version
```
ldd libIcmCore.so
```
If the response showed like message below, you need to update your gcc version.
```
./libIcmCore.so: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version GLIBCXX_3.4.26 not found (required by ./libIcmCore.so)
linux-vdso.so.1 (0x00007fffce16e000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007ffa05f2a000)
```
> [How to update gcc version in Ubuntu](https://tuxamito.com/wiki/index.php/Installing_newer_GCC_versions_in_Ubuntu)
## Build and Install cmake
To build this project, cmake version 3.16 and above is required.
```
sudo apt-get install libssl-dev
sudo apt-get purge cmake
cd /tmp
wget https://github.com/Kitware/CMake/releases/download/v3.17.2/cmake-3.17.2.tar.gz
tar -xzvf cmake-3.17.2.tar.gz
cd cmake-3.17.2/
./bootstrap
sudo make -j4
sudo make install
```
## Install boost C++
1. Download and decompress [ICU 64.2](https://github.com/unicode-org/icu/releases/tag/release-64-2)
2. Configure and build ICU in the source folder
```
cd icu/source
./configure
make
```
> Referring to [ICU Official Web Site](http://www.linuxfromscratch.org/blfs/view/9.0/general/icu.html)
Install as root
```
sudo make install
```
If you didn't configure to customized target path, default install path is **/usr/local/lib/icu/64.2**
3. Download and decompress [boost C++ 1.70.0](https://www.boost.org/users/history/version_1_70_0.html)
4. Build and install boost C++
```
cd boost_1_70_0
./bootstrap.sh
./b2
sudo ./b2 install
```
5. Build boost C++ with ICU support
```
sudo ./bjam --with-regex -sHAVE_ICU=1 -sICU_PATH=/usr/local/lib/icu/64.2 -a install
```
There should be more libboost libraries in /usr/local/lib after this step.
* Referring to [boost C++ document](https://www.boost.org/doc/libs/1_70_0/libs/regex/doc/html/boost_regex/install.html) Building With Unicode and ICU Support section
* Referring to [Installation Troubleshooting](https://github.com/mapnik/mapnik/wiki/InstallationTroubleshooting#boost-undefined-symbols)
6. Check the dependancy
```
# ldd libIcmCore.so
./libIcmCore.so: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version GLIBCXX_3.4.26 not found (required by ./libIcmCore.so)
linux-vdso.so.1 (0x00007fffce16e000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007ffa05f2a000)
libicuuc.so.64 => not found
libboost_regex-gcc9-mt-d-x64-1_70.so.1.70.0 => not found
libboost_locale-gcc9-mt-d-x64-1_70.so.1.70.0 => not found
libboost_chrono-gcc9-mt-d-x64-1_70.so.1.70.0 => not found
libboost_system-gcc9-mt-d-x64-1_70.so.1.70.0 => not found
libboost_thread-gcc9-mt-d-x64-1_70.so.1.70.0 => not found
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ffa05b8c000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007ffa05974000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ffa05755000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ffa05364000)
/lib64/ld-linux-x86-64.so.2 (0x00007ffa065df000)
```
There are still some library missing we should fix the linking manually.
7. Fix library linking
Most of all library could be found under /usr/local/lib
```
sudo ln -s /usr/local/lib/libboost_regex.so /usr/lib/x86_64-linux-gnu/libboost_regex-gcc9-mt-d-x64-1_70.so.1.70.0
sudo ln -s /usr/local/lib/libboost_locale.so /usr/lib/x86_64-linux-gnu/libboost_locale-gcc9-mt-d-x64-1_70.so.1.70.0
sudo ln -s /usr/local/lib/libboost_chrono.so /usr/lib/x86_64-linux-gnu/libboost_chrono-gcc9-mt-d-x64-1_70.so.1.70.0
sudo ln -s /usr/local/lib/libboost_system.so /usr/lib/x86_64-linux-gnu/libboost_system-gcc9-mt-d-x64-1_70.so.1.70.0
sudo ln -s /usr/local/lib/libboost_thread.so /usr/lib/x86_64-linux-gnu/libboost_thread-gcc9-mt-d-x64-1_70.so.1.70.0
sudo ln -s /usr/local/lib/libicuuc.so.64 /usr/lib/x86_64-linux-gnu/libicuuc.so.64
sudo ln -s /usr/local/lib/libicudata.so.64 /usr/lib/x86_64-linux-gnu/libicudata.so.64
sudo ln -s /usr/local/lib/libicui18n.so.64 /usr/lib/x86_64-linux-gnu/libicui18n.so.64
```
8. Check the dependancy again
```
# ldd IcmCore/libIcmCore.so
linux-vdso.so.1 (0x00007ffc684d8000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f5d40580000)
libicuuc.so.64 => /usr/local/lib/libicuuc.so.64 (0x00007f5d40140000)
libboost_regex-gcc9-mt-d-x64-1_70.so.1.70.0 => /usr/lib/x86_64-linux-gnu/libboost_regex-gcc9-mt-d-x64-1_70.so.1.70.0 (0x00007f5d3fe64000)
libboost_locale-gcc9-mt-d-x64-1_70.so.1.70.0 => /usr/lib/x86_64-linux-gnu/libboost_locale-gcc9-mt-d-x64-1_70.so.1.70.0 (0x00007f5d3fb94000)
libboost_chrono-gcc9-mt-d-x64-1_70.so.1.70.0 => /usr/lib/x86_64-linux-gnu/libboost_chrono-gcc9-mt-d-x64-1_70.so.1.70.0 (0x00007f5d3f989000)
libboost_system-gcc9-mt-d-x64-1_70.so.1.70.0 => /usr/lib/x86_64-linux-gnu/libboost_system-gcc9-mt-d-x64-1_70.so.1.70.0 (0x00007f5d3f787000)
libboost_thread-gcc9-mt-d-x64-1_70.so.1.70.0 => /usr/lib/x86_64-linux-gnu/libboost_thread-gcc9-mt-d-x64-1_70.so.1.70.0 (0x00007f5d3f563000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f5d3f1c5000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f5d3efad000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f5d3ed8e000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5d3e99d000)
/lib64/ld-linux-x86-64.so.2 (0x00007f5d40c80000)
libicudata.so.64 => /usr/local/lib/libicudata.so.64 (0x00007f5d3cd5b000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f5d3cb57000)
libicui18n.so.64 => /usr/local/lib/libicui18n.so.64 (0x00007f5d3c5ab000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f5d3c3a3000)
```
## Build the project
1. During the first time building, you should configure the libmodbus folder with current environment
```
cd icm_modbus/3rdparty/libmodbus
./autogen.sh
./configure
```
2. Build the project
```
cd icm_modbus
make
```