新GSL是否与log4cpp不兼容?

时间:2015-10-11 04:11:59

标签: c++ visual-studio visual-c++

如果我只包含GSL标题,那么一切都很糟糕。如果我只包含log4cpp标题,那么一切都是hunky dory。但是,如果我包括两者,特别是log4cpp优先和GSL秒,那么我会得到以下错误(MSVC 2015):

3>c:\project\msvc\deps\source\gsl\include\string_view.h(82): warning C4003: not enough actual parameters for macro 'max'
3>c:\project\msvc\deps\source\gsl\include\string_view.h(82): error C2589: '(': illegal token on right side of '::'
3>c:\project\msvc\deps\source\gsl\include\string_view.h(82): error C2988: unrecognizable template declaration/definition
3>c:\project\msvc\deps\source\gsl\include\string_view.h(82): error C2059: syntax error: '::'
3>c:\project\msvc\deps\source\gsl\include\string_view.h(97): warning C4003: not enough actual parameters for macro 'max'
3>c:\project\msvc\deps\source\gsl\include\string_view.h(97): error C2589: '(': illegal token on right side of '::'
3>c:\project\msvc\deps\source\gsl\include\string_view.h(97): error C2988: unrecognizable template declaration/definition
3>c:\project\msvc\deps\source\gsl\include\string_view.h(97): error C2059: syntax error: '::'

有谁知道为什么?这是一个重现的简单项目:

的CMakeLists.txt:

project(log4cpp_gsl_compat)

include(ExternalProject)
set_property(DIRECTORY PROPERTY EP_BASE "${CMAKE_CURRENT_BINARY_DIR}/deps")

ExternalProject_Add(gsl
    URL https://github.com/Microsoft/GSL/archive/3fd9f249da093ea1b73ec4135e9d8ad0b991d75b.tar.gz # rev 5 Oct 2015
    URL_HASH MD5=1fc79c1e548c500672ba9cb710d54471

    # Header-only library; there's nothing to configure, build or install
    CONFIGURE_COMMAND ""
    BUILD_COMMAND ""
    INSTALL_COMMAND ""
)

ExternalProject_Add(log4cpp
    URL http://skylineservers.dl.sourceforge.net/project/log4cpp/log4cpp-1.1.x%20%28new%29/log4cpp-1.1/log4cpp-1.1.1.tar.gz
    URL_HASH MD5=1e173df8ee97205f412ff84aa93b8fbe

    # Don't worry about building for now; just trying to get past a header compile error
    CONFIGURE_COMMAND ""
    BUILD_COMMAND ""
    INSTALL_COMMAND ""
)

add_executable(log4cpp_gsl_compat main.cpp)
set_property(TARGET log4cpp_gsl_compat PROPERTY CXX_STANDARD 14)

target_include_directories(log4cpp_gsl_compat PUBLIC
    "${CMAKE_CURRENT_BINARY_DIR}/deps/Source/gsl/include"
    "${CMAKE_CURRENT_BINARY_DIR}/deps/Source/log4cpp/include"
)

main.cpp中:

#include <log4cpp/Category.hh>
#include <gsl.h>

int main(const int argc, const char* argv[])
{
    // ...

    return 0;
}

0 个答案:

没有答案