unix环境下编译问题

淡定从容我自繁华 2012-12-17 05:23:17
大家好,首先请教大家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环境的错误
...全文
233 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
引用 7 楼 zhangxun2007 的回复:
这是环境变量没有配置,一般在/etc/profile文件中添加或新增LIBRARY_PATH 假设APP=应用程序目录,即你要安装的程序目录 添加: LIBRARY_PATH=$APP/lib:$LIBRARY_PATH 新增: LIBRARY_PATH=$APP/lib
按照你这个思路,问题顺利解决,非常感谢各位的指导
  • 打赏
  • 举报
回复
赵老师的境界我拍马也追不上,你那个土造mylog我才疏学浅看不懂呢,要不你还是教我解决这个问题好了
赵4老师 2012-12-18
  • 打赏
  • 举报
回复
要不干脆摒弃log4cpp,用我这个土造mylog:
#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;
}
zhangxun2007 2012-12-18
  • 打赏
  • 举报
回复
这是环境变量没有配置,一般在/etc/profile文件中添加或新增LIBRARY_PATH 假设APP=应用程序目录,即你要安装的程序目录 添加: LIBRARY_PATH=$APP/lib:$LIBRARY_PATH 新增: LIBRARY_PATH=$APP/lib
  • 打赏
  • 举报
回复
请问一下我这个安装log4cpp的方法对不对啊?总感觉这么安装不行呢
赵4老师 2012-12-18
  • 打赏
  • 举报
回复
百度不成换Google试了吗?
wintree 2012-12-17
  • 打赏
  • 举报
回复
引用 4 楼 songjinwu 的回复:
引用 2 楼 wallwind 的回复:表示找不到fstream这几个库,,,是不是没安装c++的东西还是没装g++编译器,还是没有连接到c++库杀的 应该是没有连接到库。如果是没连接到库,请问该怎么做啊?
知道原因了,在 http://linuxmafia.com/faq/Admin/ld-lib-path.html 要加上链接参数 g++ -Xlinker -R/usr/local/lib -o"demo" demo.o -ltest 不加-R虽然也可以把可执行程序编译出来,但执行时会找不到动态库
  • 打赏
  • 举报
回复
引用 2 楼 wallwind 的回复:
表示找不到fstream这几个库,,,是不是没安装c++的东西还是没装g++编译器,还是没有连接到c++库杀的
应该是没有连接到库。如果是没连接到库,请问该怎么做啊?
  • 打赏
  • 举报
回复
引用 1 楼 mymtom 的回复:
楼主的系统有C++编译器吗?
你好,编译器是有的。这个问题可能是环境里面引用错误导致的
wintree 2012-12-17
  • 打赏
  • 举报
回复
表示找不到fstream这几个库,,,是不是没安装c++的东西还是没装g++编译器,还是没有连接到c++库杀的
mymtom 2012-12-17
  • 打赏
  • 举报
回复
楼主的系统有C++编译器吗?

64,682

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧