Collector C + + code in red Hat versions of operating system porting problems

Source: Internet
Author: User
Tags log log snmp command access

As a result of the company's project needs, the collector C + + code in Red Hat different versions of the operating system to transplant, there are many problems, so write this article to do a comprehensive summary.First, we introduce the functions of some collectors:Responds to server server requests, maintains access to physical devices, accesses physical devices periodically using SNMP protocols, obtains required data, and stores databases.the environment in which the collector operates: Programming Languages  :C + +Operating System   :RHAS2.1, rh9.0,rhas4.4compiler       :GCC version 3.2.2 20030222 (Red Hat Linux 3.2.2-5) and GCC version 3.4.6 20060404 (Red Hat 3.4.6-3), gcc version 2.96 200007 (Red Hat Linux 7.2 2.96-108.1)  The third party development package used by the collector: log4cpp-0.3.5rc3        : Write log log Development Kit net-snmp-5.2.1            : SNMP Development Kit unixodbc-2.2.11        : sqlserver2k Access SQL interface freetds-0.64-stable     &nbsp: sqlserver2k Access SQL Interface ace                               &NBSP: Cross-operating system C + + development platform   snmp++                         : SNMP Development Kit expat                             &NBSP: expat  is an API for parsing XML configuration files       porting to different operating systems, the most problematic is the porting of Third-party development packages,  For example:      under Platform RHAS2.1, only use ACE5.4.1 and Log4cpp-0.3.5rc3zdsmodi.tar Development package, otherwise the compilation is unsuccessful;      under platform RH9.0, you can only use ACE5.4.1 and LOG4CPP-0.3.5RC 3.TAR.GZ Development Package, otherwise the compilation is unsuccessful,      under platform RHAS4.4, can use ACE5.5 and log4cpp-0.3.5rc3.tar.gz development package;   & nbsp The development of their own code in accordance with the C + + standard developed, is basically a recompile. is summarized as follows: first, the use of the log development package is modified, because the early use of the RHAS2.1 operating system, the high version of the LOG4CPP-0.3.5RC3 is not supported, the low version is not supported. I found Dedian's log4cpp log from the Internet. CPP,. h source files, copied to the  LOG4CPP-0.3.5RC3 directory, incredibly compiled, and can also use the API to write log logs. That's lucky. Later, the platform uses RHAS4.4 and RH9.0, and you can use the high version of LOG4CPP-0.3.5RC3. Second, the use of net-snmp-5.2.1  is mainly used to start the snmpd waiting process on the Linux machine, the collector to read some of the configuration information on the PC.       under the Red Hat 9 platform Net-snmp in the compiler will be a problem:/usr/bin/ld:cannot find-lelf, then need to install two RPM bzip2-devel- 1.0.2-8.i386.rpm, elfutils-devel-0.76-3.i386.rpm, recompile.      under Red hat as4,4 platform, compile error,/usr/lib/libpopt.so:could not read symbols:file in wrong format
The corresponding popt in each Makefile file is removed and recompiled can be passed. Third, sqlserver2k access to the SQL interface package unixODBC-2.2.11 and freetds-0.64-stable, is used to access the Linux platform under the Windows Platform SQLSERVER2K Data development package, in the porting operating system Time, the use of the development package with the TSQL or ISQL command access to the database can be normal access, with the use of the corresponding API is always reported incorrect error prompts, because the user name, password coding problems, to use the following statements can be: char *charset = NUL L
SetLocale (Lc_all, "");
char* locale = setlocale (Lc_all, NULL);

Dbsetlcharset (Mlogin, "iso-8859-1");
Dbsetlnatlang (Mlogin, "us_english"); Another danger is that the high version of SQL Server database may not be able to access the database in the TDS protocol support, and then there may be a problem. Iv. snmp++ is the API of my most familiar SNMP protocol, but it is the first time in Linux, some code such as Snmpget, etc. Do not yet compile, and makefile also write bad, need to reorganize, mainly is no time. Five, in the porting of different compilers in the compiler will also have problems, in the compiler gcc3.2.2, mainly using Var-args.h functions such as var_start,var_end, and RHAS4.4 use is gcc3.4.6, which uses the C + + standard function library std -args.h, it's not a function that supports var-args.h, so you need to migrate, and the porting code just shows the following example.         This is mainly because the code does not strictly follow the standard C + + to write the problem. In RHAS2.1 and RH9. 0 uses the gcc3.2.2, its code is: #include <varargs.h> int getallelemtext (xmlfile,nodename,va_alist)
Char *xmlfile;
Char *nodename;
Va_dcl
{

Char *pnodename;
Va_list ap;
Int J;

Va_start (AP);
for (j=0;; J + +)
{
Pnodename = Va_arg (Ap,char *);
if (!pnodename)
Break

#ifdef DEBUG
printf ("no:[%d]pnodename=[%s]/n", j,pnodename);
#endif
}
Va_end (AP);

return 0;
The gcc3.4.6 in RHAS4.4 only supports std-arg.h, so its corresponding code is as follows: #include <stdarg.h>
int Getallelemtext (char* xmlfile,char* nodename, ...)
{
Char *pnodename;
Va_list ap;
Int J;

Va_start (Ap,nodename);
for (j=0;; J + +)
{
Pnodename = Va_arg (Ap,char *);
if (!pnodename)
Break #ifdef DEBUG
printf ("no:[%d]pnodename=[%s]/n", j,pnodename);
#endif

}
Va_end (AP);

return 0;
In gcc3.2, the following code is capable of compiling and running normally unsigned int pos = mpacketstr.find_first_of (":");
if (pos = = String::npos)
{
Cfilelog::instance ()->log (Getpid (), "Cappresponse", "Parse", "Response has Not:char", cfilelog::info);
return 1;
However, in gcc3.4.6, although it is possible to compile through, there is a warning error: Warning:comparison is always true due to limited range of data type, change the above code to this Can: String::size_type pos = mpacketstr.find_first_of (":");
if (pos = = String::npos)
{
Cfilelog::instance ()->log (Getpid (), "Cappresponse", "Parse", "Response has Not:char", cfilelog::info);
return 1;
The ACE uses the most problems. In the RHAS2.1 platform, the high version of ACE can not be compiled on it, the highest only support ace5.4.1 version, miserable, but it took a long time to attempt to compile success, it is not, in the web for the ground to find reasons, only in an ace commercial support site found RHAS2.1 the highest only support Ace5         .4.1 Version of, I that depressed ah. In the RH9.0 platform, the high version of the ace5.5 can not be compiled on it, can only use the ace5.4.1 version of the RHAS4.4 platform, ace5.4.1 Incredibly also compiled, this time I learned good, first on the internet to see the discovery, RHAS4.4 platform under the most Low can only support ace5.4.7, the original and waste, a Center under the highest version of the ace5.5, in the ACE directory
%mkdir Build
%CD Build
%make
%cp/home/creco/ats/ace_wrappers/build/ace/.libs/*/home/creco/ats/ace_wrappers/lib I didn't install using make install just copy the library files to A directory I can find the program, who would like my code always reported ace error, find a long time to find the problem, found that the ACE directory did not find the corresponding config.h file, can be compiled under the directory build/ace copy to the Ace_root/ace directory can be.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.