zoukankan      html  css  js  c++  java
  • vs2017环境下编译log4cpp-1.1.3

    Log4cpp是一个开源的C++类库,它提供了在C++程序中使用日志和跟踪调试的功能。最新版本为1.1.3。项目地址为:http://log4cpp.sourceforge.net/

    该版本指供了msvc6,msvc7(2003),msvc10(2010)的编译解决方案,其它编译解决方案可以从中选择一个进行调整。

    以下是我msvc2017环境下的编译过程。

    1、下载并解压得到log4cpp源码;

    2、复制一份msvc10子目录并重命名为msvc2017;

    3、用vs2017打开msvc10.sln解决方案,会提示需要升级,点击OK接受升级;

    blob.png

    4、尝试单独编译log4cpp动态库,出现如下错误信息:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    1>------ Build started: Project: log4cpp, Configuration: Debug Win32 ------
    1>Performing Custom Build Tools
    1>'"vsvars32.bat"' 不是内部或外部命令,也不是可运行的程序
    1>或批处理文件。
    1>D:log4cppmsvc2017log4cpp..NTEventLogCategories.mc : error : unable to open output file - Debug" -r Debug"NTEventLogCategories.h
    1>MC: Unable to open D:log4cppmsvc2017log4cpp..NTEventLogCategories.mc for input
    1>Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
    1>
    1>Copyright (C) Microsoft Corporation.  All rights reserved.
    1>
    1>
    1>CUSTOMBUILD : fatal error RC1110: could not open DebugNTEventLogCategories.rc
    1>
    1>Microsoft (R) Incremental Linker Version 14.11.25508.2
    1>Copyright (C) Microsoft Corporation.  All rights reserved.
    1>
    1>LINK : fatal error LNK1181: cannot open input file 'DebugNTEventLogCategories.res'
    1>Done building project "log4cpp.vcxproj" -- FAILED.
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    这是对“NTEventLogCategories.mc”文件编译的报错信息,该文件是采用“自定义编译”方法,用mc.exe命名行编译。

    5、打开“NTEventLogCategories.mc”文件人编译属性,如下图:

    blob.png

    6、修改Command Line。为了好看,我做了一下换行,换行后代码如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    "$(VS100COMNTOOLS)vsvars32.bat" 
     
    if not exist $(OutDir) md $(OutDir)
     
    mc.exe -h "$(OutDir)" -r "$(OutDir)" "$(ProjectDir)..\%(Filename).mc"
     
    rc.exe -r -fo "$(OutDir)%(Filename).res" "$(OutDir)%(Filename).rc"
     
    link.exe /MACHINE:IX86 -dll -noentry -out:"$(OutDir)NTEventLogAppender.dll" "$(OutDir)%(Filename).res"

    7、删除第一行,并在第三行的"$(OutDir)"改为"$(OutDir)"。(即在后面多加一个号)。改完后的全文如下:

    1
    2
    3
    4
    5
    6
    7
    if not exist $(OutDir) md $(OutDir)
     
    mc.exe -h "$(OutDir)" -r "$(OutDir)" "$(ProjectDir)..\%(Filename).mc"
     
    rc.exe -r -fo "$(OutDir)%(Filename).res" "$(OutDir)%(Filename).rc"
     
    link.exe /MACHINE:IX86 -dll -noentry -out:"$(OutDir)NTEventLogAppender.dll" "$(OutDir)%(Filename).res"

    8、重新编译,上面的问题没了,但又出现了另一个错误。错误信息如下:

    1
    2
    3
    4
    1>d:log4cppsrcsnprintf.c(524): error C2084: function 'int snprintf(char *const ,const ::size_t,const char *const ,...)' already has a body
    1>c:program files (x86)windows kits10include10.0.15063.0ucrtstdio.h(1938): note: see previous definition of 'snprintf'
    1>d:log4cppsrcsnprintf.c(538): error C2084: function 'int vsnprintf(char *const ,const ::size_t,const char *const ,va_list)' already has a body
    1>c:program files (x86)windows kits10include10.0.15063.0ucrtstdio.h(1428): note: see previous definition of 'vsnprintf'

    9、根据错误提示定位到snprintf.c文件第524行,部份文本如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    /*
     * If the system does have snprintf and the portable routine is not
     * specifically required, this module produces no code for snprintf/vsnprintf.
     */
    #if !defined(HAVE_SNPRINTF) || defined(PREFER_PORTABLE_SNPRINTF)
     
    #if !defined(NEED_SNPRINTF_ONLY)
    int portable_snprintf(char *str, size_t str_m, const char *fmt, /*args*/ ...) {
      va_list ap;
      int str_l;
     
      va_start(ap, fmt);
      str_l = portable_vsnprintf(str, str_m, fmt, ap);
      va_end(ap);
      return str_l;
    }

    10、可以看出log4cpp对snprintf做了重新定义,但vs2017已自带snprintf函数,所以,我们可以用开关“HAVE_SNPRINTF”来禁用这段代码。

    blob.png

    11、重新编译,搞定。

    12、其它工程同样用以上方法修正。

    此文转自:http://www.jiazi.cn/blog/?id=55

  • 相关阅读:
    CF 1083 A. The Fair Nut and the Best Path
    2434: [Noi2011]阿狸的打字机
    HDU 6086 Rikka with String
    HDU 2825 Wireless Password
    异常处理与补充模块
    面向对象
    初始socket
    面向对象的进阶(组合和继承)
    初始面向对象
    python之其他模块的用法
  • 原文地址:https://www.cnblogs.com/luciaark/p/7910583.html
Copyright © 2011-2022 走看看