實時CORBA平台TAO的安裝和使用
這裡以ACE-5.4+TAO-1.4+CIAO-0.4.tar.gz為例。
一. Win32+VC6.0下編譯和安裝ACE和TAO
将網上下載下傳的TAO軟體包解壓縮到某個目錄(本文為C:\),該目錄下會有ACE_wrappers目錄。
請按照以下步驟來執行:
1. 建立兩個環境變量:
ACE_ROOT=C:\ACE_wrappers
TAO_ROOT=C:\ACE_wrappers\tao
為系統變量PATH加上C:\ACE_wrappers\bin
2. 在ACE_ROOT\ace(即C:\ACE_wrappers\ace)目錄下用VC建立一個空的頭檔案config.h,裡面包含一句:#include "ace/config-win32.h"
以說明是要在win32平台下進行編譯。
3.用VC打開TAO和ACE的工程檔案:ACE_ROOT\tao\taoace.dsw,開始編譯ACE
和TAO. 注意ACE和TAO有Debug和Release兩個版本. 你在開發自己的程式時,
如果是Debug版的程式, 必須連結Debug版的TAO庫, 如果是Release版的程式,
必須連結Release版的TAO庫.
3.在編譯taoace.dsw之前需要先安裝OpenSSL,而OpenSSL安裝前需安裝腳本語言Perl
安裝好後會在C槽下生成檔案夾perl
Perl安裝後,開始安裝OpenSSL
(1) Firstly you should run Configure:
> perl Configure VC-WIN32
(2) Next you need to build the Makefiles and optionally the assembly language
files:
_If you don't want to use the assembly language files at all then run:
Openssl-0.9.6> ms\do_ms
(3)Now to install
在DOS環境下
Follow the steps below:
$ md c:\openssl
$ md c:\openssl\bin
$ md c:\openssl\lib
$ md c:\openssl\include
$ md c:\openssl\include\openssl
$ copy /b inc32\* c:\openssl\include\openssl
$ copy /b out32dll\ssleay32.lib c:\openssl\lib
$ copy /b out32dll\libeay32.lib c:\openssl\lib
$ copy /b out32dll\ssleay32.dll c:\openssl\bin
$ copy /b out32dll\libeay32.dll c:\openssl\bin
$ copy /b out32dll\openssl.exe c:\openssl\bin
詳情見openssl-0.9.6檔案夾下的文本檔案INSTALL
安裝好後會在C槽下生成檔案夾openssl
4. 打開VC環境下 Project>setting>設定 選擇Win32 Debug
5.打開VC環境下 Tools>Options>Directories
加入以下内容:
Executable File:
C:\ACE_wrappers\bin
C:\ACE_WRAPPERS\TAO\TAO
Include File:
C:\ACE_wrappers\
C:\ACE_wrappers\TAO
C:\ACE_WRAPPERS\TAO\tao
C:\ACE_wrappers\TAO\orbsvcs
C:\openssl\include
C:\ACE_wrappers\bin
Library Files:
C:\ACE_wrappers\ace
C:\ACE_wrappers\TAO\tao
C:\ACE_wrappers\TAO\orbsvcs\orbsvcs
C:\openssl\lib
C:\ACE_wrappers\bin
C:\ACE_wrappers\usrlib(見後面說明)
Source Files:
C:\ACE_wrappers\ace
C:\ACE_wrappers\TAO\tao
C:\ACE_wrappers\TAO\orbsvcs\orbsvcs
C:\ACE_wrappers\bin
6.taoace.dsw
VC環境下 組建>批組建,選擇你需要的工程配置(所有的帶Win32 Debug的檔案),然後“全部重建”,此過程可能持續二至四個鐘頭
産生的.lib檔案位于C:\ACE_wrappers\ace\下
産生的.dll檔案位于C:\ACE_wrappers\bin\下
VC下的TAO的使用(以書上的簡單程式為例)
本程式的主要目的是使客戶機擷取格林威治目前時間(詳細程式見書)
1.C:\下建立CORBA檔案夾,檔案夾下建立三個檔案夾:time、Server、Client
2.首先編寫IDL的定義。在VC環境下建立一個C++ Sourse File檔案,編寫IDL的定義,儲存為time.idl(time 檔案夾下)
3.修改配置
project-->settings…-->C/C++ àCategory:Code Generation àUse run-time library設定為“Debug Multithreaded DLL”
project-->settings…-->C/C++ àCategory:Preprocessor àAdditional include directories中添加C:\ACE_wrappers
project-->settings…àLink àCategory:Input àObject/library modules:中添加aced.lib taod.lib,并在下面的Additional library path裡面添加路徑C:\ACE_wrappers\ace
(注:編譯時發現還需要加很多類庫,是以最好将ACE_wrappers下的所有.lib檔案放到一個檔案夾下,将每個.lib都加到Object/library modules下,然後再将檔案夾的路徑加到Library Files:中,見前文,這樣就能保證編譯時所需的所有庫都包含在其中了)
4.編譯IDL。找到IDL編譯器tao_idl.exe(一般在ACE_wrappers\bin下)。打開DOS環境
輸入C:\ACE_wrappers\bin\tao_idl C:\CORBA\time\time.idl 編譯idl。将生成的9個檔案分别拷到Server和Client目錄下。
(The IDL compiler generates 9 files from each .idl file. The file names are obtained by taking the IDLbasename and appending the following suffixes (see the list of TAO's IDL compileroptions on how to get different suffixes for these files:)
- Client stubs, i.e., *C.h, *C.i, and *C.cpp. Pure client applications only need to #include and link with these files.
- Server skeletons, i.e., *S.h, *S.i, and *S.cpp. Servers need to #include and link with these files.
- Server skeleton templates, i.e., *S_T.h, S_T.i, and *S_T.cpp. Some C++ compilers do not like template and non-template code in the same files, so TAO's IDL compiler generates these files separately.
TAO's IDL compiler creates separate *.i and *S_T.* files to improve the performance of the generated code. For example, the *.i files enable you to compile with inlining enabled or not, which is useful for trading-off compile-time and run-time performance. Fortunately, you only need to #include the client stubs declared in the *C.h file and the skeletons in the *S.h file in your code.)
5.編譯伺服器端程式。開VC環境,建立一個Win32控制台工程,命名為Server,放在Server目錄下(空工程)。在工程下建立一個C++ Sourse File,将伺服器端代碼寫入(注意加入頭檔案#include"timeS.h"|#include"timeC.h")。将Server目錄下的檔案Server.cpp、times.cpp、timeC.cpp、timeS_T.cpp加入Sourse Files目錄,将timeC.h、timeS.h、timeS_T.h、timeS_T.i加入Header Files目錄。全部重建。得到Server.exe檔案。
6.編譯用戶端程式。前面的步驟同伺服器端。将Client.cpp、timeC.cpp加入Sourse Files目錄,将timeC.h、timeS.h、timeC.i加入Header Files目錄。全部重建。得到Client.exe檔案。
7.運作程式。打開DOS環境,運作SERVER.exe ,它将輸出一個引用給它的Time對象IOR。
Trouble:發現無法将IOR傳遞給客戶機,改進伺服器端程式
ofstream out("ior");
……
out << str <<endl;
out.close();
将得到的字元串放到一個“ior”的檔案中,将它提出寫入客戶機端的程式中,得到格林威治時間。