• ACE的编译和安装,for windows、Linux


    一. Windows下for MSVC的安装与配置

    http://download.dre.vanderbilt.edu/ 下载

    我们用的是ACE-5.4+TAO-1.4+CIAO-0.4.zip,Windows下解压缩该压缩包到目标路径(设为D:\ACE_wrappers ),

    创建文件:$ACE_ROOT/ace/config.h,增加一行:
    #include "ace/config-win32.h"

    如果是在Windows 9x/Me下,需要在$ACE_ROOT/ace/config.h中#include语句前加入:
    #define ACE_HAS_WINNT4 0

    如果想使用standard C++ header,需要在$ACE_ROOT/ace/config.h中#include语句前加入:
    #define ACE_HAS_STANDARD_CPP_LIBRARY 1

    如果想把MFC作为静态库链接到ACE(If you prefer to link MFC as a static library into ACE),
    则需要在$ACE_ROOT/ace/config.h中#include语句前加入:
    #define ACE_HAS_MFC 1

    如果想生成ACE静态库或在工程中使用ACE静态库,都需要定义以下宏:
    ACE_AS_STATIC_LIBS


    打开工程,D:\ACE_wrappers\ace.dsw,编译生成以下库:

    代码
    ace.dll/ace.lib (DLL release)
    aced.dll
    /aced.lib(DLL debug)
    acemfc.dll
    /acemfc.lib (MFC DLL release)
    acemfcd.dll
    /acemfcd.lib(MFC DLL debug)

    aces.lib (Static library release)
    acesd.lib (Static library debug)

    这些库可分别实现了Debug/Release, MFC/Non-MFC, Static/Dynamic library.

    其中前四个的dll在D:\ACE_WRAPPERS\bin目录下, 所有对应的.lib库文件在D:\ACE_WRAPPERS\ace下。

    ACE是网络通讯中间件,如果机器没有装网卡,就仿真一个,比如可以从控制面板选装MS Loopback Adapter。

    接下来我们创建一个新的工程,如果机器上装了不同版本的ACE,需要针对某个版本配置,方法如下:

    1. 配置C/C++ tab

    (1) Code Generation category中应选择合适的选项:
    Multithreaded和Multithreaded DLL是for Release版的
    Debug Multithreaded和Debug Multithreaded DLL是for Debug版的

    (2) $(ACE_ROOT)路径的配置:
    如果需要针对不同版本ACE灵活配置的话,则需要设置Preprocessor category中"Additional include directories"
    这一项,指明特定版本ACE所在的路径,比如D:\ACE_wrappers

    2. 链接到特定版本的ACE库。

    (1) 在Project/Setting/Link的Input category下 "Additional library path"中增加特定版本的ACE库文件路径,
    比如D:\ACE_wrappers\ace,然后将D:\ACE_wrappers\bin目录下对应的dll拷贝到工程文件所在路径下,或者在环境
    变量PATH中加入D:\ACE_wrappers\bin。

    (2) 在Project/Setting/Link的Input category下"Object/library modules" 中指定需要包含的ACE库(*.lib)


    如果只装了一个ACE,可采用对所有工程都生效的缺省配置,方法如下:

    1. 添加环境变量:
    ACE_ROOT:  D:\ACE_wrappers
    PATH 中加入:D:\ACE_wrappers\bin

    2. 设置VS的路径:
    Include files包含:D:\ACE_wrappers
    library files包含:D:\ACE_wrappers\ace

    此后,就可以在工程中指定需要包含的ACE库(*.lib)后正常使用了。


    二. Linux下的安装与配置


    1.安装
    以用户aceuser为例
    (1)下载ACE-5.4+TAO-1.4+CIAO-0.4.tar.gz(其它版本的也一样)


    (2)解压之
        #cd /home/aceuser/ace
        #tar -xzvf  ACE-5.4+TAO-1.4+CIAO-0.4.tar.gz

    (3)
      #vi /home/aceuser/.bashrc
      加入下面两行:
      export ACE_ROOT=/home/aceuser/ace/ACE_wrappers
      export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ACE_ROOT/ace

      
      并使这些环境变量生效(运行source 或者重新登陆)。

    (4)
      #cd /home/aceuser/ace/ACE_wrappers/ace/
      #cp ./config-linux.h ./config.h
      #cd ../include/makeinclude/
      #ln -s ./platform_linux.GNU ./platform_macros.GNU

    (5)编译
      #cd /home/aceuser/ace/ACE_wrappers/
      创建一个目录:
      #mkdir build
      #cd build
      #../configure && make && make install

      对于ACE-5.4+TAO-1.4+CIAO-0.4这个版本,不能ACE-5.4+TAO-1.4+CIAO-0.4.zip这个压缩包,否则会出现如下错误:
      ln -s libACE.so.5.4.0 libACE.so
      chmod a+rx libACE.so.5.4.0
      : command not foundpers/bin/ace_components: line 10
      '/home/aceuser/ace/ACE_wrappers/bin/ace_components: line 31: syntax error near unexpected token 'in
      '/home/aceuser/ace/ACE_wrappers/bin/ace_components: line 31: ' case $1 in
      make[1]: ***[ACE_COMONENTS] Error 2
      make[1]: Leaving directory '/home/aceuser/ace/ACE_wrappers/ace'
      make: ***[all] Error 2

      如果换成ACE-5.4+TAO-1.4+CIAO-0.4.tar.gz就没有任何问题了

      编译时也可以根据自己的需要设置编译选项
      #make [options]
      下面是option的描述:
    Option         Description
    debug=1|0   Enable or disable debugging in the built library or program. Default is enabled (1).
    optimize=1|0   Turn compiler optimization on or off. Default is off (0).
    buildbits=bits   Explicitly select, for example, 32-bit or 64-bit build target. Default is the compiler's default for the build machine. This option works for AIX, Solaris, and HP-UX.
    exceptions=1|0  Enable or disable exception handling. Default is platform specific but usually enabled (1).
      inline=1|0   Enable or disable inlining of many of ACE's methods. Default is platform specific but usually enabled (1).
    templates=model  Specify how templates are instantiated. Most common values for model are automatic, the default for compilers that support it well, and explicit, requiring source code directives to explicitly instantiate needed templates (see Section 1.6.1).
      static_libs=1|0  Build and use static libraries. Default is to not build static libraries (0).

    2.使用
    下面介绍如何从零开始建立一个使用ACE的工程。并使之run起来

    (1)编写使用了ACE的代码
    (2)编写Makefile

    代码
    BIN = hello_ace
    FILES
    = Piece2 Piece3
    SRC
    = $(addsuffix .cpp,$(FILES))
    OBJ
    = $(addsuffix .o,$(FILES))
    BUILD
    = $(VBIN)
    #
    ---------------------------------------------------------
    # Include macros and targets
    #
    ---------------------------------------------------------
    include $(ACE_ROOT)
    /include/makeinclude/wrapper_macros.GNU
    include $(ACE_ROOT)
    /include/makeinclude/macros.GNU
    include $(ACE_ROOT)
    /include/makeinclude/rules.common.GNU
    include $(ACE_ROOT)
    /include/makeinclude/rules.nonested.GNU
    include $(ACE_ROOT)
    /include/makeinclude/rules.bin.GNU
    include $(ACE_ROOT)
    /include/makeinclude/rules.local.GNU

    以上的Makefile包含3个cpp文件hello_ace.cpp、Piece2.cpp和Piece3.cpp

    (3)编译
       #make
      如果程序没有任何问题,现在程序应该就可以运行了。

    (4)常见错误
      错误1:
      “Cannot open include file: ace/SOCK_Acceptor.h: No such file or directory”
      解决方法:
      Project->settings->C/C++: Preprocessor的Additional include directories中加入$ACE_ROOT,如E:/ACE_wrappers
      错误2:
      “You must link against multi-threaded libraries when using ACE (check your project settings)”
      解决方法:
      Project->settings->C/C++: Code Generation 的Use run-time library : Debug Multithreaded Dll
      错误3:
      “error C2065: ACE_ERROR : undeclared identifier”
      “error C2065: ACE_DEBUG : undeclared identifier”
      解决方法:
      在原马中加入#i nclude ace/Log_Msg.h
      错误4:“error C4716: ace_main_i : must return a value”
      解决方法:
      在main中加入return 0;
      错误5:
      “error LNK2001: unresolved external symbol __declspec(dllimport) int __cdecl”
      解决方法:
      Project->settings->Link->Input: Object/library Modules加入aced.lib ,Additional Library Path中加入$ACE_ROOT\ace,如E:\ACE_wrappers\ace
      编译client中遇到的问题:
      错误6:
      error C2039: sprintf : is not a member of ACE_OS
      解决方法:#i nclude ace/OS_NS_stdio.h
      错误7:error C2039: strlen : is not a member of ACE_OS
      解决方法:#i nclude ace/OS_NS_string.h
      错误8:无法找到动态链接库aced.dll于指定的路径
      解决方法:为系统变量PATH加上D:\ACE_wrappers\bin
      静态包含:
       工程-设置-C/C++-预处理程序定义中加入 ,ACE_AS_STATIC_LIBS

    -----------------------------接下来我们开始学习一下写hello ace.-------------------------------------
     

    代码
    //---------------------------------------------------------------
    //@file: hello.cpp

    #include
    <stdio.h>
    #include
    "ace/Log_Msg.h"
    #include
    "ace/OS_main.h"
    int ACE_TMAIN(int argc, ACE_TCHAR* argv[])
    {
    ACE_DEBUG((LM_DEBUG,ACE_TEXT(
    "hello world.\n")));
    return 0;
    }

    //-------------------------------------------------------------
    再写hello.mpc

    project(hello) :aceexe{
    exename
    = hello
    after
    += hello

    Source_Files {
    hello.cpp
    }
    }


    ------------------------------------------------------------
    用MPC实用工具生成Makefile文件
    $ACE_ROOT/bin/mwc.pl -type make hello.mpc
    您将得到Makefile和Makefile.hello两个文件
    运行make
    可以得到可执行文件hello
    ./hello
    得到
    Hello world.

  • 相关阅读:
    (转)图文并茂详解VisualStudio使用技巧一
    使用VS2005的 ClickOnce 技术实现按需下载组件
    (转)VS2005 SP1发布,解决只能创建WebSite,无法创建Web Application项目的问题
    .NET设计规范笔记1
    No error message available, result code: E_FAIL(0x80004005)
    SSL SettingsClient certificates
    处理程序“PageHandlerFactoryIntegrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”
    添加IIS_IUSRS
    DTS,复制到同一服务器下
    在IIS7.5上配置Https,SSL
  • 原文地址:https://www.cnblogs.com/sevenyuan/p/1757854.html
Copyright © 2020-2023  润新知