Linux下配置和使用ACE笔记
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