ubuntu 14.04下是能夠經過下面這條指令安裝ice3.5的java
sudo apt-get install libzeroc-ice35-dev
主要包括兩部分:ice3.5.1.tar.gz和第三方依賴包ThirdParty-Sources-3.5.1.tar.gz
linux
第三方依賴包中只含有berkely DB和mcpp兩個依賴包,還缺乏bzip、expat、openssl。
c++
$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
$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
$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 installgit
$tar jxvf expat-2.1.1.tar.bz2 $cd expat-2.1.1/ $./configure --prefix=/usr $make && sudo make install
$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 installgithub
$tar zxvf v3.5.1.tar.gz $cd ice-3.5.1/cpp/ (這裏只是安裝了ice的c++模塊) $make && sudo make install
大概等了20多分鐘報錯,ubuntu
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修改爲下面內容:bash
# ********************************************************************** # # 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,經過。測試
創建一個print目錄,在該目錄下:ui
創建ice文件demo.icethis
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