Linux下配置和使用ACE筆記

來源:互聯網
上載者:User

1.  下載 ACE 5.7.
從 http://download.dre.vanderbilt.edu/ 下載 ACE+TAO+CIAO-5.7.tar.gz包。

2.  解壓
將壓縮包copy到linux目錄/data/ACE裡,然後解壓, tar -zxvf ACE+TAO+CIAO-5.7.tar.gz。
解壓後的目錄是 /data/ACE_wrappers.

3.  配置config.h和platform_macros.GNU。
官方文檔上是這麼寫的:
Create a configuration file, $ACE_ROOT/ace/config.h, that includes the appropriate platform/compiler-specific header configurations from the ACE source directory. For example:
#include "ace/config-linux.h"

Create a build configuration file, $ACE_ROOT/include/makeinclude/platform_macros.GNU, that contains the appropriate platform/compiler-specific Makefile configurations, e.g.,
include $(ACE_ROOT)/include/makeinclude/platform_linux.GNU

在實際操作中也可以直接建立一個軟連結:
cd $ACE_ROOT/ace
ln -s config-linux.h config.h
cd $(ACE_ROOT)/include/makeinclude/
ln -s platform_linux.GNU platform_macros.GNU

3.  configure
    cd ACE_wrappers/
    mkdir build
    ../configure
    等幾分鐘後configure完成。

4.  make
    在ACE_wrappers/build目錄下, 執行$make
    make完以後,在/data/ACE/ACE_wrappers/build/ace/.libs/目錄下,能找到libACE.so和libACE-5.7.so.
   
    make特別慢,尤其是ACE+TAO+CIAO在一起的這個包,make要好幾個小時。如果TAO和CIAO用不著的話,只下載ACE的就可以了,可以省點時間。 

5.  install
    在ACE_wrappers/build下執行#make install
    make install之後,會在/usr/local/include下找到好幾個ace相關的檔案夾,裡面有include需要的標頭檔。
    在/usr/local/lib下找到一堆ACE相關的.so檔案,包括libACE.so等等。
   
    linux下系統尋找include檔案的順序是(這段是網上摘抄的):
    /usr/include
    /usr/local/include
    /usr/lib/gcc-lib/i386-linux/2.95.2/include
    /usr/lib/gcc-lib/i386-linux/2.95.2/../../../../include
    /usr/lib/gcc-lib/i386-linux/2.95.2/../../../../i386-linux/include
    尋找lib檔案的順序是
    /lib
    /usr/lib
    而ACE的lib所在的目錄是 /usr/local/lib,所以要注意為lib配置環境變數。

 

6.  配置環境變數
    配置.bashrc
    ~/.bashrc:
    ACE_ROOT=/home/cs/faculty/schmidt/ACE_wrappers; export ACE_ROOT
    LD_LIBRARY_PATH=$ACE_ROOT/lib:$LD_LIBRARY_PATH;export LD_LIBRARY_PATH
    配置完環境變數執行以下 . ~/.bashrc
    或者登出重新登入一下。

    配置ld.so.conf
    開啟/etc/ld.so.conf
    本來內容是如下:
    include ld.so.conf.d/*.conf
    我們添加ace路徑後變成如下
    include ld.so.conf.d/*.conf
    /usr/local/lib
    儲存退出
    然後執行    ldconfig

7  用gcc測試一下。
   寫小程式:

hello.cpp

#include "ace/OS.h"
#include "ace/Log_Msg.h"
int main (int argc, char *argv[])
{
ACE_DEBUG((LM_DEBUG,"Hello, ACE! "));
ACE_OS::exit(1);
return 0;
}

編譯:
[root@linuxvm1 test]# gcc -p -o hello hello.cpp -I /data/ACE/ACE_wrappers -L /data/ACE/test/ -l ACE -lz -lm
編譯的時候-l要寫ACE,而不是libACE.so
執行:
[root@linuxvm1 test]# ./hello
./hello: error while loading shared libraries: libACE-5.7.so: cannot open shared object file: No such file or directory
[root@linuxvm1 test]# export LD_LIBRARY_PATH=/data/ACE/test
[root@linuxvm1 test]# ./hello
Hello,ACE!

8  用KDevelop測試一下。
把/data/ACE/ACE_wrappers/examples/C++NPv1裡面的Iteractive_Logging_Server(Iteractive_Logging_Server.cpp, Iteractive_Logging_Server.h,Logging_Handler.cpp,Logging_Handler.h,Logging_Server.cpp,Logging_Server.h)和Logging_Client(Logging_Client.cpp)兩個project加到KDevelop裡面。
然後配置一下用到的lib:在Project Options->Configure Options -> General->Linker flags(LDFLAGS)中添加 /usr/local/lib/libACE.so.
然後build。
執行#./iteractive_logging_server 9999
執行#./logging_client 9999

執行成功。

 

 

9. eclipse中配置:
   Project -> Properties -> C/C++ Build -> Settings -> Tool Settings -> GCC C++ Linker -> Libraries
   Libraries(-l)添加:ACE
   Library search path(-L)添加: /usr/local/lib/

10.在VS2005上建立工程的問題。
主要是要在工程屬性裡做一下配置,具體配置就參考內建的那些例子裡面的工程的配置就可以了。
隨便開啟一個工程,挨個對一下上面的配置,就可以跑了。

註:有時候會報undefined reference to的錯誤,可能是.so檔案沒有找到。比如這種情況。
[root@linuxvm1 test]# gcc -p -o hello hello.cpp -I /data/ACE/ACE_wrappers -L /data/ACE/test/libACE.so -lz -lm
/tmp/ccPse7FN.o(.text+0x22): In function `main':
: undefined reference to `ACE_Log_Msg::last_error_adapter()'
/tmp/ccPse7FN.o(.text+0x2a): In function `main':
: undefined reference to `ACE_Log_Msg::instance()'
/tmp/ccPse7FN.o(.text+0x44): In function `main':
: undefined reference to `ACE_Log_Msg::conditional_set(char const*, int, int, int)'
/tmp/ccPse7FN.o(.text+0x59): In function `main':
: undefined reference to `ACE_Log_Msg::log(ACE_Log_Priority, char const*, ...)'
/tmp/ccPse7FN.o(.text+0x66): In function `main':
: undefined reference to `ACE_OS::exit(int)'
/tmp/ccPse7FN.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

參考網址:
http://www.dre.vanderbilt.edu/~schmidt/DOC_ROOT/ACE/ACE-INSTALL.html#aceinstall
http://www.cs.wustl.edu/~schmidt/ACE_wrappers/ACE-INSTALL.html#installpre
http://wuerping.cnblogs.com/archive/2005/03/24/124498.aspx
http://www.linuxidc.com/Linux/2009-06/20419.htm

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.