其他分享
首页 > 其他分享> > log4cxx vs2019编译

log4cxx vs2019编译

作者:互联网

使用VS2019编译“apache-log4cxx-0.10.0"的详细教程附带测试代码和编译好的库。

一:下载需要的压缩文件

在log4cxx官方主页:https://logging.apache.org/log4cxx/latest_stable/

下载https://archive.apache.org/dist/logging/log4cxx/0.10.0/apache-log4cxx-0.10.0.zip

在github地址:http://archive.apache.org/dist/apr/

下载:apr-1.6.5-win32-src.zip,apr-iconv-1.2.2-win32-src.zip,apr-util-1.2.10-win32-src.zip

将三个压缩包解压到同一个目录,apr-1.6.5改名为apr,apr-util-1.2.10改名为apr-util,apr-iconv-1.2.2改名为apr-iconv

二:修改宏定义及文件内容

1:进入apr-util\include修改apr_ldap.hw的APR_HAS_LDAP宏定义为0,apu.hw的APU_HAVE_APR_ICONV宏定义为0

2:进入apache-log4cxx-0.10.0执行configure.bat,进入projects,打开log4cxx.dsw,升级工程

修改log4cxx.vcxproj文件:AdditionalDependencies最后添加uuid.lib;rpcrt4.lib;

log4cxx\apr\include中添加一个文件:
apr_escape_test_char.h

内容:

/* this file is automatically generated by gen_test_char, do not edit. "make include/private/apr_escape_test_char.h" to regenerate. */
//编译 apr 1.6.5 需要的头文件 apr_escape_test_char.h
#define T_ESCAPE_SHELL_CMD     (1)
#define T_ESCAPE_PATH_SEGMENT  (2)
#define T_OS_ESCAPE_PATH       (4)
#define T_ESCAPE_ECHO          (8)
#define T_ESCAPE_URLENCODED    (16)
#define T_ESCAPE_XML           (32)
#define T_ESCAPE_LDAP_DN       (64)
#define T_ESCAPE_LDAP_FILTER   (128)

static const unsigned char test_char_table[256] = {
    224,222,222,222,222,222,222,222,222,222,223,222,222,223,222,222,222,222,222,222,
    222,222,222,222,222,222,222,222,222,222,222,222,6,16,127,22,17,23,49,17,
    145,145,129,80,80,0,0,18,0,0,0,0,0,0,0,0,0,0,16,87,
    119,16,119,23,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,23,223,23,23,0,23,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,23,23,23,17,222,222,222,222,222,222,222,222,222,222,222,222,222,
    222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,
    222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,
    222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,
    222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,
    222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,
    222,222,222,222,222,222,222,222,222,222,222,222,222,222,222,222 
};

 打开 apr/apr.vcxproj:
删除以下内容:

<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">type .\include\apr.hw &gt; .\include\apr.h</Command>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Creating apr.h from apr.hw</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.\include\apr.h;%(Outputs)</Outputs

<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">type .\include\apr.hw &gt; .\include\apr.h</Command>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Creating apr.h from apr.hw</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">.\include\apr.h;%(Outputs)</Outputs>

修改src\main\cpp\stringhelper.cpp文件:
添加:#include <iterator>
修改src\main\include\log4cxx\log4cxx.h文件

//原来
#if defined(LOG4CXX_STATIC)
#define LOG4CXX_EXPORT
//改为
#if defined(LOG4CXX_STATIC) || (defined(_MSC_VER) && _MSC_VER >= 1916)
#define LOG4CXX_EXPORT
 
//原来
#if defined(_MSC_VER) && !defined(LOG4CXX_STATIC) && defined(LOG4CXX)
//改为
#if defined(_MSC_VER) && _MSC_VER < 1916 && !defined(LOG4CXX_STATIC) && defined(LOG4CXX)
 
//原来
#elif defined(_MSC_VER) && !defined(LOG4CXX_STATIC)
//改为
#elif defined(_MSC_VER) && _MSC_VER < 1916 && !defined(LOG4CXX_STATIC)

 这时编译程序就能编译过啦

三:如何生成.lib文件

修改”log4cxx.h“

由于在代码编辑器中LOG4CXX_EXPORT无法指定是导出还是导入,所以我重新后面加了一下:
在预处理宏中添加LOG4CXX,此时就为导出了!

#if defined(LOG4CXX)
#define LOG4CXX_EXPORT __declspec(dllexport)
#else
#define LOG4CXX_EXPORT __declspec(dllimport)
#endif


四:测试生成的库

#include<log4cxx/logger.h>

#include<log4cxx/propertyconfigurator.h>
using namespace log4cxx;

int main()
{
    //获得一个Logger,这里使用了RootLogger
	//加载log4cxx的配置文件,这里使用了属性文件

	PropertyConfigurator::configure("../config/log4cxx.properties");
	LOG4CXX_INFO(rootLogger, "判断各题错误正确");
    return 0;
}

 五:编译log4xx的压缩文件和编译好的生成库

 

 六:Visual Studio版本与MSVC版本号的对应关系

MSC    1.0   _MSC_VER == 100
MSC    2.0   _MSC_VER == 200
MSC    3.0   _MSC_VER == 300
MSC    4.0   _MSC_VER == 400
MSC    5.0   _MSC_VER == 500
MSC    6.0   _MSC_VER == 600
MSC    7.0   _MSC_VER == 700
MSVC++ 1.0   _MSC_VER == 800
MSVC++ 2.0   _MSC_VER == 900
MSVC++ 4.0   _MSC_VER == 1000 (Developer Studio 4.0)
MSVC++ 4.2   _MSC_VER == 1020 (Developer Studio 4.2)
MSVC++ 5.0   _MSC_VER == 1100 (Visual Studio 97 version 5.0)
MSVC++ 6.0   _MSC_VER == 1200 (Visual Studio 6.0 version 6.0)
MSVC++ 7.0   _MSC_VER == 1300 (Visual Studio .NET 2002 version 7.0)
MSVC++ 7.1   _MSC_VER == 1310 (Visual Studio .NET 2003 version 7.1)
MSVC++ 8.0   _MSC_VER == 1400 (Visual Studio 2005 version 8.0)
MSVC++ 9.0   _MSC_VER == 1500 (Visual Studio 2008 version 9.0)
MSVC++ 10.0  _MSC_VER == 1600 (Visual Studio 2010 version 10.0)
MSVC++ 11.0  _MSC_VER == 1700 (Visual Studio 2012 version 11.0)
MSVC++ 12.0  _MSC_VER == 1800 (Visual Studio 2013 version 12.0)
MSVC++ 14.0  _MSC_VER == 1900 (Visual Studio 2015 version 14.0)
MSVC++ 14.1  _MSC_VER == 1910 (Visual Studio 2017 version 15.0)
MSVC++ 14.11 _MSC_VER == 1911 (Visual Studio 2017 version 15.3)
MSVC++ 14.12 _MSC_VER == 1912 (Visual Studio 2017 version 15.5)
MSVC++ 14.13 _MSC_VER == 1913 (Visual Studio 2017 version 15.6)
MSVC++ 14.14 _MSC_VER == 1914 (Visual Studio 2017 version 15.7)
MSVC++ 14.15 _MSC_VER == 1915 (Visual Studio 2017 version 15.8)
MSVC++ 14.16 _MSC_VER == 1916 (Visual Studio 2017 version 15.9)
MSVC++ 14.2  _MSC_VER == 1920 (Visual Studio 2019 Version 16.0)
MSVC++ 14.21 _MSC_VER == 1921 (Visual Studio 2019 Version 16.1)
MSVC++ 14.22 _MSC_VER == 1922 (Visual Studio 2019 Version 16.2)

七:本文参考的博客

https://blog.csdn.net/xie1xiao1jun/article/details/86230667

 

 

 

标签:VER,vs2019,apr,MSV,C++,编译,MSC,222,log4cxx
来源: https://blog.csdn.net/cai_niaocainiao/article/details/117988727