微服务:ICE 入门之 编译环境搭建

        俗话说分享是学习的重要途径之一,提高自己的过程,学习,研究,应用,解决问题,总结,分享;闲来无事时便可总结下自己学习过的知识,把之前遇到过的问题也上升到方法论,把自己踩过的坑也罗列出来以防重蹈覆辙!好了,废话少说,书归正转!

       本系列讲座全部是以C++部分为题讲解ICE的各个部分,从入门到精通吧;说的有点高大上了,说白了就是对我自己知识点的一个梳理吧,里面有什么错误和误导的地方也请大方的指出~~;工欲善其事必先利其器,我们的后台服务全部使用linux作为开发环境,对,ubuntu or debian都可以,哦,对了,最好64位。那接下来我们开始一阳指和六脉神剑的修炼之旅。使用的是ubuntu server 64位,其实那个版本无所谓,版本新了,系统中g++编译器支持版本高些; 

berli@ubuntu64:~/Test$ cat /etc/issue
Ubuntu 15.10 
 l

更新ubuntu的最新安装信息

berli@ubuntu64:~$ sudo apt-get update

安装git以便我们获取最新的源代码,一个类似svn的东东,但git是比较先进和代表未来发展方向的,建议学习下

<span style="font-size:18px;">berli@ubuntu64:~$ sudo apt-get install git</span>

下载ICE最新的代码

https://github.com/zeroc-ice/ice

berli@ubuntu64:~/Test$ git clone --recursive https://github.com/zeroc-ice/ice.git




安装编译所需要的各种依赖包,否则直接编译时会报下面的错误

sudo apt-get install libssl-dev liblmdb-dev libbluetooth-dev libdbus-1-dev libbz2-dev

make: pkg-config: Command not found
make: pkg-config: Command not found
Compiling [amd64-static] src/Slice/Grammar.cpp
Compiling [amd64-static] src/Slice/Scanner.cpp
Compiling [amd64-static] src/Slice/CPlusPlusUtil.cpp
Compiling [amd64-static] src/Slice/JavaUtil.cpp
Compiling [amd64-static] src/Slice/Parser.cpp
Compiling [amd64-static] src/Slice/PythonUtil.cpp
Compiling [amd64-static] src/Slice/PHPUtil.cpp
。。。。。
/usr/bin/ld: cannot find -lmcpp
/usr/bin/ld: cannot find -lcrypto
collect2: error: ld returned 1 exit status

In file included from src/IceBT/Engine.h:14:0,
                 from src/IceBT/Engine.cpp:10:
src/IceBT/Config.h:16:33: fatal error: bluetooth/bluetooth.h: No such file or directory

src/IceBT/DBus.cpp:15:23: fatal error: dbus/dbus.h: No such file or directory
compilation terminated.



Berkeley DB下载,编译,安装

下载:
Skip to end of metadata
$ wget https://zeroc.com/download/berkeley-db/db-5.3.28.NC.tar.gz

解压:

$ tar xzf db-5.3.28.NC.tar.gz

必须给bdb打patch,否则编译后无法使用

$ cd db-5.3.28.NC/build_unix
$  patch -p0 < ../db/patch.db.5.3.28
$ ../dist/configure --enable-cxx --enable-java

编译&安装

$ make

$ sudo make install

On a 64-bit platform, you need to create a lib64 symbolic link to the lib directory:

$ cd /opt/db53
$ ln -s lib lib64
安装mcpp,从zeroic的给的github下载源码
Clone the zeroc-inc/mcpp repository hosted on GitHub:
$ git clone https://github.com/zeroc-ice/mcpp.git

进入目录,make,sudo make install就可以了


也可以直接下载mcpp,按照下面步骤执行命令,编译,安装

http://prdownloads.sourceforge.net/mcpp/mcpp-2.7.2.tar.gz?download
tar xvf mcpp-2.7.2.tar.gz  
cd mcpp-2.7.2  
patch -p0 < ../mcpp/patch.mcpp.2.7.2  
  ./configure CFLAGS=-fPIC --enable-mcpplib --disable-shared  
  make && make install 

OK,安装上面依赖的各种开源库,我们现在请我们的主角ICE登场,万事俱备只欠东风~,进入cd ice/cpp目录,开始make,

经过漫长的编译时间后,执行sudo make install完成了安装;到此,我们完成了ice编译环境的搭建。



ICE默认是安装到/opt目录,我们要拷贝到/usr/local/bin(当然你也可以/usr/bin)

把ICE的bin文件拷贝到/usr/local/bin

sudo cp /opt/Ice-3.7a3/bin/ /usr/local/bin/
测试下slice2cpp




原文地址:https://www.cnblogs.com/mtcnn/p/9410041.html