zoukankan      html  css  js  c++  java
  • log4cxx日志库在Windows+VS2017上的编译使用

    项目中用到了log4cxx,但是Debug版本运行时老是提示找不到Properities::setProperty?怀疑是提供的库有问题,所以尝试源码来重新编译一下。
    log4cxx官方主页:https://logging.apache.org/log4cxx/latest_stable/
    github地址:https://github.com/apache/logging-log4cxx
    log4cpp,log4cplus,log4cxx这几个什么关系?
    Log4cxx需要依赖于APR。
    Log4cpp较log4c移植性稍差些。
    Log4c基本上都是一些纯c的东西,移植性比其他二者都要好
    log4cplus: 简洁, 下载的包编译顺利, 测试例子也能顺利运行。
    log4cxx: 臃肿, 需要引用apr(Apache Portable Runtime), 最痛苦的是老是编译不了
    log4cpp: 落后, 最后更新于2007年,而且下载的包不完整。

    我尝试在Windows+VS2017上编译log4cxx,但是按照网上的方法无法编译成功,会提示一堆错误,让人望而却步。
    最终找到了前人已经整理好的版本(https://download.csdn.net/download/xie1xiao1jun/10908599),根据需要稍加修改后即可正常使用。
    我修改的部分:log4cxx.h
    // definitions used when using static library
    #if defined(LOG4CXX_STATIC) || (defined(_MSC_VER) && _MSC_VER >= 1900)
    #define LOG4CXX_EXPORT
    // definitions used when building DLL
    #elif defined(LOG4CXX)
    #define LOG4CXX_EXPORT __declspec(dllexport)
    #else
    // definitions used when using DLL
    #define LOG4CXX_EXPORT __declspec(dllimport)
    #endif
    我的情况,由于上述在代码编辑器中LOG4CXX_EXPORT无法指定是导出还是导入,所以我重新后面加了一下:
    在预处理宏中添加LOG4CXX,此时就为导出了!
    #if defined(LOG4CXX)
    #define LOG4CXX_EXPORT __declspec(dllexport)
    #else
    #define LOG4CXX_EXPORT __declspec(dllimport)
    #endif

    使用VS2017,设置x64 Debug,设置生成动态库,会成功编译生成log4cxx.lib和log4cxx.dll
    如何使用,请参考官方文档:https://logging.apache.org/log4cxx/latest_stable/usage.html

  • 相关阅读:
    ojdbc14.jar
    Redis
    ftl转成word
    Swagger
    SpringBoot
    条件注解
    Spring SpringMVC MyBatis
    Spring介绍
    Django_mysql表查询
    Django01
  • 原文地址:https://www.cnblogs.com/MakeView660/p/11819861.html
Copyright © 2011-2022 走看看