zoukankan      html  css  js  c++  java
  • ubuntu14.04下安装ice3.5.1

    ubuntu 14.04下是可以通过下面这条指令安装ice3.5的

    sudo apt-get install libzeroc-ice35-dev

    1. 从这里下载ice源文件

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

    2. 安装第三方依赖

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

    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 

    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 --prefix=/usr --enable-mcpplib --disable-shared  
    $make && make install 

    2.3) 安装bzip[下载]

    $tar zxvf bzip2-1.0.6.tar.gz
    $cd bzip2-1.0.6/
    $make && make install

    错误提示:/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

    2.4) 安装expat[下载]

    $tar jxvf expat-2.1.1.tar.bz2
    $cd expat-2.1.1/
    $./configure --prefix=/usr
    $make && sudo make install

    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

    错误提示:/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

    3. 安装ice

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

    大概等了20多分钟报错,

    make[4]: Leaving directory `/root/ice_ws/ice_source/ice-3.5.1/cpp/demo/book/map_filesystem'
    make[3]: Leaving directory `/root/ice_ws/ice_source/ice-3.5.1/cpp/demo/book'
    make[2]: Leaving directory `/root/ice_ws/ice_source/ice-3.5.1/cpp/demo'
    make[1]: Leaving directory `/root/ice_ws/ice_source/ice-3.5.1/cpp'
    making all in java
    make[1]: Entering directory `/root/ice_ws/ice_source/ice-3.5.1/java'
    ant -emacs
    make[1]: ant: Command not found
    make[1]: *** [all] Error 127
    make[1]: Leaving directory `/root/ice_ws/ice_source/ice-3.5.1/java'
    make: *** [all] Error 1

    发现是java环境需要的ant,直接进入makefile进行修改,因为此处开发只需要用到c++,并且需要进行移植,所以将makefile修改成下面内容:

    # **********************************************************************
    #
    # Copyright (c) 2003-2013 ZeroC, Inc. All rights reserved.
    #
    # This copy of Ice is licensed to you under the terms described in the
    # ICE_LICENSE file included in this distribution.
    #
    # **********************************************************************
    
    SUBDIRS            = cpp 
    CLEAN_SUBDIRS        = cpp
    DEPEND_SUBDIRS        = cpp
    INSTALL_SUBDIRS        = cpp
    
    all::
        @for subdir in $(SUBDIRS); 
        do 
            echo "making all in $$subdir"; 
            ( cd $$subdir && $(MAKE) all ) || exit 1; 
        done
    
    clean::
        @for subdir in $(CLEAN_SUBDIRS); 
        do 
            echo "making clean in $$subdir"; 
            ( cd $$subdir && $(MAKE) clean ) || exit 1; 
        done
    
    depend::
        @for subdir in $(DEPEND_SUBDIRS); 
        do 
            echo "making depend in $$subdir"; 
            ( cd $$subdir && $(MAKE) depend ) || exit 1; 
        done
    
    install::
        @for subdir in $(INSTALL_SUBDIRS); 
        do 
            echo "making install in $$subdir"; 
            ( cd $$subdir && $(MAKE) install ) || exit 1; 
        done
    
    test::
        @for subdir in $(SUBDIRS); 
        do 
            echo "making test in $$subdir"; 
            ( cd $$subdir && $(MAKE) test ) || exit 1; 
        done
    
    cpp::
        echo "making all in cpp";
        ( cd cpp && $(MAKE) all ) || exit 1;

    然后make && make  install,通过。

     5. 测试用例

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

    建立ice文件demo.ice

    module demo
    {
        interface printer
        {
            void printerstr(string msg);    
        };
    
    };

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

    $slice2cpp demo.ice

    发现没有slice2cpp这条指令,添加系统环境gedit /etc/environment

    将生成的bin目录导入,或者在~/.bashrc里添加PATH

    :/opt/Ice-3.5.1/bin

    运行上面命令,报错如下:

    slice2cpp: error while loading shared libraries: libSlice.so.35: cannot open shared object file: No such file or directory

     编译生成的环境加入到系统环境中gedit  ~/.bashrc

    #在PATH中找到可执行文件程序的路径。
    export PATH =$PATH:/opt/Ice-3.5.1/bin
    
    #g++找到头文件的路径
    CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/opt/Ice-3.5.1/include
    export CPLUS_INCLUDE_PATH
    
    #找到动态链接库的路径
    LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/Ice-3.5.1/lib
    export LD_LIBRARY_PATH

    保存,source ~/.bashrc,重新执行上述命令,OK,在print目录下生成demo.h和demo.cpp。

    编写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;
    }

    编写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;
    }

    编译并运行客户端和服务端,如果hello world打印出来,那么就是安装成功了。

    $ g++ demo.cpp server.cpp -lIce -L/opt/Ice-3.5.1/lib -lIceUtil -lpthread -o server
    $ g++ demo.cpp client.cpp -lIce -L/opt/Ice-3.5.1/lib -lIceUtil -lpthread -o client
    $ ./server
    
    $./client
    Hello World!

    至此,安装成功!!!

    原文参考http://blog.csdn.net/w1282109144/article/details/51426361

  • 相关阅读:
    数据库之主表、从表、主键、外键
    eclipse编写js代码没有提示
    思维导图xmind的使用方法
    整理一下Apache与Tomcat的关系
    全栈开发者,一个很好的自学编程网站
    svn文件被锁不能提交的解决办法
    在SQL Server数据库中执行存储过程很快,在c#中调用很慢的问题
    php安装redis扩展
    PHP点击按钮拷贝
    PHP文件下载
  • 原文地址:https://www.cnblogs.com/wanzaiyimeng/p/5981244.html
Copyright © 2011-2022 走看看