ubuntu14.04下安装ice3.5.1


ubuntu1404下是可以通过下面这条指令安装ice3.5的,如果没有,那就源码装吧

sudo apt-get install libzeroc-ice35-dev
  • 1

1. 从这里下载ice源文件

主要包括两部分:ice3.5.1.tar.gz和第三方依赖包ThirdParty-Sources-3.5.1.tar.gz
  • 1
  • 2

2. 安装第三方依赖

第三方依赖包中只含有berkely DB和mcpp两个依赖包,还缺少bzip、expat、openssl。
  • 1
  • 2

2.1) 安装berkely DB

$tar xvf ThirdParty-Sources-3.5.1.tar.gz   
$cd ThirdParty-Sources-3.5.1  
$tar zxvf db-5.3.21.NC.tar.gz
$cd db-5.3.21.NC/
$patch -p0 < ../db/patch.db.5.3.21 
$cd build_unix/
$../dist/configure --prefix=/usr --enable-cxx
$make && make install 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

2.2) 安装mcpp

$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 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

2.3) 安装bzip[下载]

$tar zxvf bzip2-1.0.6.tar.gz
$cd bzip2-1.0.6/
$make && make install
  • 1
  • 2
  • 3

2.4) 安装expat[下载]

$tar jxvf expat-2.1.1.tar.bz2
$cd expat-2.1.1/
$./configure --prefix=/usr
$make && sudo make install
  • 1
  • 2
  • 3
  • 4

2.5) 安装openssl[下载]

$unzip OpenSSL_0_9_8-stable.zip
$cd openssl-OpenSSL_0_9_8-stable/
$./config --prefix=/usr --openssldir=/usr/openssl(openssldir默认为/usr/ssl/openssl,需要修改,否则默认安装路径会找不到。)
$make
$make test
$sudo make install
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

3. 安装ice

$tar zxvf v3.5.1.tar.gz
$cd ice-3.5.1/cpp/ (这里只是安装了ice的c++模块)
$make && sudo make install
  • 1
  • 2
  • 3

4. ice错误提示

  • 错误提示:/usr/lib.ld:Error:cannot find -lmcpp
    解决:应该是mcpp没有安装成功,是不是忘记上面步骤中的patch了,重新安装。
  • 错误提示:/usr/bin/ld: /usr/local/lib/libbz2.a(bzlib.o): relocation R_ARM_THM_MOVW_ABS_NC against `BZ2_crc32Table’ can not be used when making a shared object; recompile with -fPIC
    /usr/local/lib/libbz2.a: error adding symbols: Bad value
    解决:bzip没有装好,一般是64 位 电脑才会出现。上面已经提示了recompile with -fPIC。所以回到bzip目录,修改Makefile文件,CC = gcc —> CC = gcc- fPIC,再次make && make install
  • 错误提示:/usr/bin/ld: /usr/lib/gcc/arm-linux-gnueabihf/4.9/../../../../lib/libssl.a(s23_meth.o): relocation R_ARM_THM_MOVW_ABS_NC against `a local symbol’ can not be used when making a shared object; recompile with -fPIC
    解决:这个错误和问题2是一样的,因此修改Makefile文件,CC = gcc —> CC = gcc- fPIC,再次make && make install
  • 错误提示:openssl安装时候的问题
    解决:先下了一个版本1.1.0的,安装出现问题,回到版本0.9.8。

5. 测试用例

建立一个print目录,在该目录下:

  • 建立ice文件demo.ice
module demo
{
    interface printer
    {
        void printerstr(string msg);    
    };

};
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

运行下面的命令,会在print目录下生成demo.h和demo.cpp。

$slice2cpp demo.ice
$ls print/
demo.ice   demo.h   demo.cpp
  • 1
  • 2
  • 3
  • 编写ice服务端server.cpp
#include <Ice/Ice.h>
#include <demo.h>
using namespace demo;
using namespace std;
class PrinterI : public printer {
    public:
        virtual void printerstr(const string & s,
                const Ice::Current &);
};
void
PrinterI::
printerstr(const string & s, const Ice::Current &)
{
    cout << s << endl;
}
int
main(int argc, char* argv[])
{
    int status = 0;
    Ice::CommunicatorPtr ic;
    try {
        ic = Ice::initialize(argc, argv);
        Ice::ObjectAdapterPtr adapter
            = ic->createObjectAdapterWithEndpoints(
                    "SimplePrinterAdapter", "default -p 10000");
        Ice::ObjectPtr object = new PrinterI;
        adapter->add(object,
                ic->stringToIdentity("SimplePrinter"));
        adapter->activate();
        ic->waitForShutdown();
    } catch (const Ice::Exception & e) {
        cerr << e << endl;
        status = 1;
    } catch (const char * msg) {
        cerr << msg << endl;
        status = 1;
    }
    if (ic)
        ic->destroy();
    return status;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 编写ice客户端client.cpp
#include <Ice/Ice.h>
#include <demo.h>
using namespace demo;
using namespace std;

int
main(int argc, char * argv[])
{
    int status = 0;
    Ice::CommunicatorPtr ic;
    try {
        ic = Ice::initialize(argc, argv);
        Ice::ObjectPrx base = ic->stringToProxy(
                "SimplePrinter:default -p 10000");
        printerPrx printer = printerPrx::checkedCast(base);
        if (!printer)
            throw "Invalid proxy";
        printer->printerstr("Hello World!");
    } catch (const Ice::Exception & ex) {
        cerr << ex << endl;
        status = 1;
    } catch (const char * msg) {
        cerr << msg << endl;
        status = 1;
    }
    if (ic)
        ic->destroy();
    return status;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 编译并运行客户端和服务端,如果hello world打印出来,那么就是安装成功了。
$ g++ -I. -o server demo.cpp server.cpp -lIce -lIceUtil -lpthread
$ g++ -I. -o client demo.cpp client.cpp -lIce -lIceUtil -lpthread
$ ./server

$./client
Hello World!

猜你喜欢

转载自blog.csdn.net/dddxxxx/article/details/80998210
今日推荐