首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

unix环境上编译有关问题

2013-01-04 
unix环境下编译问题大家好,首先请教大家unix服务器安装log4cpp的方法,这个百度好久没没得下面是我自己安装

unix环境下编译问题
大家好,首先请教大家unix服务器安装log4cpp的方法,这个百度好久没没得

下面是我自己安装log4cpp的方法:
我现在有了log4cpp-1.1rc1.tar.gz这个包,我把这个包放到服务器上面,然后解压,再把解压后的得到的路径:/usr2/srcs_dir/common/log4cpp/include/log4cpp/设置在系统环境变量中的LOG4CPP_HOME这个环境变量中,然后编译程序,发现报错:
Error 112: "/usr2/srcs_dir/common/log4cpp/include/log4cpp/Portability.hh", line 55 # Include file <fstream> not found.
    #include <fstream>
             ^^^^^^^^^
Error 112: "/usr2/srcs_dir/common/log4cpp/include/log4cpp/Portability.hh", line 56 # Include file <iostream> not found.
    #include <iostream>
             ^^^^^^^^^^
Error 112: "/usr2/srcs_dir/common/log4cpp/include/log4cpp/Portability.hh", line 57 # Include file <ios> not found.
    #include <ios>
             ^^^^^
Error 112: "/usr2/srcs_dir/common/log4cpp/include/log4cpp/Portability.hh", line 58 # Include file <sstream> not found.
    #include <sstream>
             ^^^^^^^^^
Error 697: "/usr2/srcs_dir/common/log4cpp/include/log4cpp/Portability.hh", line 60 # Only namespace names are valid here.
    using namespace std;
                    ^^^ 
请大家帮忙看看这个安装方法对不对,如果不对该怎么做,如果安装的正确,这个错误又该怎么解决。看错误的意思好像是C环境的错误
[解决办法]
楼主的系统有C++编译器吗?
[解决办法]
表示找不到fstream这几个库,,,是不是没安装c++的东西还是没装g++编译器,还是没有连接到c++库杀的
[解决办法]


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
    #include <windows.h>
    #include <io.h>
#else
    #include <unistd.h>
    #include <sys/time.h>
    #include <pthread.h>
    #define  CRITICAL_SECTION   pthread_mutex_t
    #define  _vsnprintf         vsnprintf
#endif
//Log{
#define MAXLOGSIZE 20000000
#define ARRSIZE(x) (sizeof(x)/sizeof(x[0]))


#include <time.h>
#include <sys/timeb.h>
#include <stdarg.h>
char logfilename1[]="MyLog1.log";
char logfilename2[]="MyLog2.log";
char logstr[16000];
char datestr[16];
char timestr[16];
char mss[4];
CRITICAL_SECTION cs_log;
FILE *flog;
#ifdef WIN32
void Lock(CRITICAL_SECTION *l) {
    EnterCriticalSection(l);
}
void Unlock(CRITICAL_SECTION *l) {
    LeaveCriticalSection(l);
}
#else
void Lock(CRITICAL_SECTION *l) {
    pthread_mutex_lock(l);
}
void Unlock(CRITICAL_SECTION *l) {
    pthread_mutex_unlock(l);
}
#endif
void LogV(const char *pszFmt,va_list argp) {
    struct tm *now;
    struct timeb tb;

    if (NULL==pszFmt
[解决办法]
0==pszFmt[0]) return;
    if (-1==_vsnprintf(logstr,ARRSIZE(logstr),pszFmt,argp)) logstr[ARRSIZE(logstr)-1]=0;
    ftime(&tb);
    now=localtime(&tb.time);
    sprintf(datestr,"%04d-%02d-%02d",now->tm_year+1900,now->tm_mon+1,now->tm_mday);
    sprintf(timestr,"%02d:%02d:%02d",now->tm_hour     ,now->tm_min  ,now->tm_sec );
    sprintf(mss,"%03d",tb.millitm);
    printf("%s %s.%s %s",datestr,timestr,mss,logstr);
    flog=fopen(logfilename1,"a");
    if (NULL!=flog) {
        fprintf(flog,"%s %s.%s %s",datestr,timestr,mss,logstr);
        if (ftell(flog)>MAXLOGSIZE) {
            fclose(flog);
            if (rename(logfilename1,logfilename2)) {
                remove(logfilename2);
                rename(logfilename1,logfilename2);
            }
            flog=fopen(logfilename1,"a");
            if (NULL==flog) return;
        }
        fclose(flog);
    }
}
void Log(const char *pszFmt,...) {
    va_list argp;

    Lock(&cs_log);
    va_start(argp,pszFmt);
    LogV(pszFmt,argp);
    va_end(argp);
    Unlock(&cs_log);
}
//Log}
int main(int argc,char * argv[]) {
    int i;
#ifdef WIN32
    InitializeCriticalSection(&cs_log);
#else
    pthread_mutex_init(&cs_log,NULL);
#endif
    for (i=0;i<10000;i++) {
        Log("This is a Log %04d from FILE:%s LINE:%d\n",i, __FILE__, __LINE__);


    }
#ifdef WIN32
    DeleteCriticalSection(&cs_log);
#else
    pthread_mutex_destroy(&cs_log);
#endif
    return 0;
}

热点排行