ACE網管平台移植Linux

來源:互聯網
上載者:User
我們的網管平台基於ACE, ODBC,SNMP ++的,都是可以跨平台的庫,但一直未進行linux下的編譯測試,這是去年移植測試時記錄的日誌。 注意移植前先要編譯好ACE, unixODBC,SNMP ++的庫。 在從VC下移植到linux(用gcc編譯)過程中記錄的一些更改項: 1)微軟windef.h檔案中定義的內容linux下不可用,包括#define MAX_PATH          260 別的還有#define DWORD unsigned int#define LPVOID void* 2)用到的ace中和NT有關的ACE_NT_Service這些東西即使是win32下其實也沒有起作用,直接屏蔽 3)微軟winsvc.h檔案中定義的內容#define SERVICE_CONTROL_SHUTDOWN       0x00000005.....這些東西即使是win32下其實也沒有起作用,直接屏蔽 4)有些大小寫有關係了, 還有include後面必須用/而不是/#include "ace/OS.H"#include "ace/Task.h"#include "dbaccess1.h"#include "include/v3.h"#include "include/snmpmsg.h"       // asn serialization class#include "include/vb.h"#include "include/oid_def.h" 5)有些文法細節gcc不允許ACE_DEBUG((LM_INFO, ACE_TEXT("%D Preparing to rebuild DB connection "                    "pool(%d)! : %t/n"), iConnPoolSize));那個換行的第二個"必須放到第二行 6)每個檔案結尾都要斷行符號,不然編譯會警示warning: no newline at end of file 7)gcc不允許到期綁定(VC下是可以通過編譯的)for (int i = 0;i < 6;i++)。。。for (i = 0;i < 128;i++)  8)warning: "NULL" redefined 9)linux(gcc)下函數至少返回void,VC下不是必須的 10) 註冊表部分只能在windows中用(查詢資料庫類型)改用SQLGetInfo讀資料庫類型 11)FormatMessage這是MFC CString的東東(comm.cpp 裡面得debug_info函數)  12)linux下用真實ip得出來的主機名稱和用127.0.0.1或0.0.0.0(預設)得出來得不一樣ACE_INET_Addr addr1(port, szAddr);//初始化,注意第二個參數填真實ip和"127.0.0.1"的區別addr1.get_host_name();//獲得主機名稱 13)常量字串不能直接轉給char*sztemp = (sztemp==0||strlen(sztemp)<1)?" ":sztemp; 14)linux不支援:itoa   strrev   strnicmp(不管大小寫比較) stricmp strset Sleep其中itoa用ACE_OS::itoa代替(strrev也就不用了),可以用以下函數類比實現或轉換成linux下的函數   #if defined(__linux__) #define MAX_PATH 260#define DWORD unsigned int#define LPVOID void*#define strnicmpstrncasecmp#define stricmpstrcasecmptypedef unsigned char       BYTE;typedef unsigned short      WORD; #define __strrevstrrevchar* strrev(char* szT){    if ( !szT )                 // 處理傳入的空串.        return "";    inti = strlen(szT);    intt = !(i%2)? 1 : 0;      // 檢查串長度.    for(intj = i-1 , k = 0 ; j > (i/2 -t) ; j-- )    {        charch = szT[j];        szT[j]   = szT[k];        szT[k++] = ch;    }    return szT;} #define _itoa   itoachar* itoa(intvalue, char* str, intradix){    int rem = 0;    int pos = 0;    charch = '!' ;    do    {        rem    = value % radix ;        value /= radix;        if ( 16 == radix )        {            if( rem >= 10 && rem <= 15 )            {                switch( rem )                {                case 10:                    ch = 'a' ;                    break;                case 11:                    ch ='b' ;                    break;                case 12:                    ch = 'c' ;                    break;                case 13:                    ch ='d' ;                    break;                case 14:                    ch = 'e' ;                    break;                case 15:                    ch ='f' ;                    break;                }            }        }        if( '!' == ch )        {            str[pos++] = (char) ( rem + 0x30 );        }        else        {            str[pos++] = ch ;        }    }while( value != 0 );    str[pos] = '/0' ;    return strrev(str);} inline void Sleep(unsigned intuseconds ){    // 1 毫秒(milisecond) = 1000 微秒(microsecond).    // Windows 的 Sleep 使用毫秒(miliseconds)    // Linux 的 usleep 使用微秒(microsecond)    // 由於原來的代碼是在 Windows 中使用的,所以參數要有一個毫秒到微秒的轉換。    usleep( useconds * 1000 );} #endif  預設庫路徑怎麼不起作用呢(bvrde裡面)?ACE_ROOT=/mnt/hgfs/ACE_wrappersexport ACE_ROOTC_INCLUDE_PATH=$ACE_ROOTexport C_INCLUDE_PATH共用庫LD_LIBRARY_PATH=$ACE_ROOT/ace;$LD_LIBRARY_PATHexport LD_LIBRARY_PATH靜態庫LIBRARY_PATH=./snmp_lib/libexport LIBRARY_PATH 後來在makefile裡面明確指定庫檔案(給ld選項使用,編譯多專案檔的單個檔案時只需指定-I路徑即可)才行: LIBS          = ./snmp_lib/lib/libsnmp++.a /                     ./snmp_lib/libdes/libdes.a /       /mnt/hgfs/igoview/ACE_wrappers/ace/libACE.so /       /usr/lib/libodbc.so轉自:http://blog.csdn.net/stephenxu111/archive/2008/05/14/2446384.aspx

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.