gabime / spdlog

Fast C++ logging library.
Other
24.3k stars 4.54k forks source link

build project failed #2713

Closed L-Super closed 1 year ago

L-Super commented 1 year ago

env:

include(FetchContent)
FetchContent_Declare(spdlog
        URL https://github.com/gabime/spdlog/archive/refs/tags/v1.10.0.tar.gz
        SOURCE_DIR ${CMAKE_SOURCE_DIR}/third_party/spdlog
        DOWNLOAD_EXTRACT_TIMESTAMP true
)
FetchContent_MakeAvailable(spdlog)
...
target_link_libraries(${PROJECT_TARGET}
        Qt5::Core
        Qt5::Gui
        Qt5::Widgets
        Qt5::Svg
        libcef_lib libcef_dll_wrapper ${CEF_STANDARD_LIBS}
        spdlog::spdlog_header_only)

code:

MainWindow::MainWindow(QWidget *parent)
    : QWidget(parent), ui(new Ui::MainWindow), isMoving(false), browserTabWidget(new BrowserTabWidget(this))
{
    ui->setupUi(this);
    setWindowFlags(Qt::CustomizeWindowHint);
    ui->verticalLayout->addWidget(browserTabWidget);
    ui->verticalLayout->setContentsMargins(QMargins(0, 0, 0, 0));
    spdlog::info("start{}", __func__ );

When I use Clion and MSVC complier build Qt application , it build failed.Error information:

C:\Users\Listening\Documents\Workplace\cxClient\third_party\spdlog\include\spdlog\fmt\bundled\format.h(2042): error C2220: 以下警告被视为错误
C:\Users\Listening\Documents\Workplace\cxClient\third_party\spdlog\include\spdlog\fmt\bundled\format.h(2042): warning C4459: “uint”的声明隐藏了全局声明
D:\Qt\5.15.2\msvc2019_64\include\QtCore/qglobal.h(275): note: 参见“uint”的声明
C:\Users\Listening\Documents\Workplace\cxClient\third_party\spdlog\include\spdlog\fmt\bundled\format.h(2197): note: 查看对正在编译的函数 模板 实例化“OutputIt fmt::v8::detail::write<Char,fmt::v8::appender,T,0>(OutputIt,T)”的引用
        with
        [
            OutputIt=fmt::v8::appender,
            Char=char,
            T=double
        ]
C:\Users\Listening\Documents\Workplace\cxClient\third_party\spdlog\include\spdlog\fmt\bundled\core.h(1611): note: 查看对正在编译的函数 模板 实例化“fmt::v8::appender fmt::v8::detail::default_arg_formatter<Char>::operator ()<double>(T)”的引用
        with
        [
            Char=char,
            T=double
        ]
C:\Users\Listening\Documents\Workplace\cxClient\third_party\spdlog\include\spdlog\fmt\bundled\core.h(1611): note: 查看对正在编译的函数 模板 实例化“fmt::v8::appender fmt::v8::detail::default_arg_formatter<Char>::operator ()<double>(T)”的引用
        with
        [
            Char=char,
            T=double
        ]
C:\Users\Listening\Documents\Workplace\cxClient\third_party\spdlog\include\spdlog\fmt\bundled\format.h(2931): note: 查看对正在编译的函数 模板 实例化“fmt::v8::appender fmt::v8::visit_format_arg<fmt::v8::detail::default_arg_formatter<Char>,Context>(Visitor &&,const fmt::v8::basic_format_arg<Context> &)”的引用
        with
        [
            Char=char,
            Context=fmt::v8::format_context,
            Visitor=fmt::v8::detail::default_arg_formatter<char>
        ]
C:\Users\Listening\Documents\Workplace\cxClient\third_party\spdlog\include\spdlog\fmt\bundled\format-inl.h(2588): note: 查看对正在编译的函数 模板 实例化“void fmt::v8::detail::vformat_to<char>(fmt::v8::detail::buffer<char> &,fmt::v8::basic_string_view<char>,fmt::v8::basic_format_args<fmt::v8::format_context>,fmt::v8::detail::locale_ref)”的引用
C:\Users\Listening\Documents\Workplace\cxClient\third_party\spdlog\include\spdlog\fmt\bundled\format.h(1270): warning C4459: “uint”的声明隐藏了全局声明
D:\Qt\5.15.2\msvc2019_64\include\QtCore/qglobal.h(275): note: 参见“uint”的声明
C:\Users\Listening\Documents\Workplace\cxClient\third_party\spdlog\include\spdlog\fmt\bundled\format.h(2052): note: 查看对正在编译的函数 模板 实例化“fmt::v8::detail::dragonbox::float_info<double>::carrier_uint fmt::v8::detail::exponent_mask<floaty>(void)”的引用
C:\Users\Listening\Documents\Workplace\cxClient\third_party\spdlog\include\spdlog\fmt\bundled\format.h(2197): note: 查看对正在编译的函数 模板 实例化“OutputIt fmt::v8::detail::write<Char,fmt::v8::appender,T,0>(OutputIt,T)”的引用
        with
        [
            OutputIt=fmt::v8::appender,
            Char=char,
            T=double
        ]
ninja: build stopped: subcommand failed.

When I changed CMakeLists.txt:

    target_link_libraries(${PROJECT_TARGET}
            Qt5::Core
            Qt5::Gui
            Qt5::Widgets
            Qt5::Svg
            libcef_lib libcef_dll_wrapper ${CEF_STANDARD_LIBS}
            spdlog)

The error info:

[1/21] Automatic MOC and UIC for target spdlog
[2/21] Building CXX object _deps\spdlog-build\CMakeFiles\spdlog.dir\spdlog_autogen\mocs_compilation.cpp.obj
[3/21] Building CXX object _deps\spdlog-build\CMakeFiles\spdlog.dir\src\file_sinks.cpp.obj
[4/21] Building CXX object _deps\spdlog-build\CMakeFiles\spdlog.dir\src\async.cpp.obj
C:\Users\Listening\Documents\Workplace\cxClient\third_party\spdlog\include\spdlog/async_logger-inl.h(62): warning C4530: 使用了 C++ 异常处理程序,但未启用展开语义。请指定 /EHsc
[5/21] Building CXX object _deps\spdlog-build\CMakeFiles\spdlog.dir\src\cfg.cpp.obj
D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\include\string(36): warning C4530: 使用了 C++ 异常处理程序,但未启用展开语义。请指定 /EHsc
D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.35.32215\include\string(79): note: 查看对正在编译的函数 模板 实例化“std::basic_istream<char,std::char_traits<char>> &std::getline<char,std::char_traits<char>,std::allocator<char>>(std::basic_istream<char,std::char_traits<char>> &&,std::basic_string<char,std::char_traits<char>,std::allocator<char>> &,const _Elem)”的引用
        with
        [
            _Elem=char
        ]
C:\Users\Listening\Documents\Workplace\cxClient\third_party\spdlog\include\spdlog/cfg/helpers-inl.h(70): note: 查看对正在编译的函数 模板 实例化“std::basic_istream<char,std::char_traits<char>> &std::getline<char,std::char_traits<char>,std::allocator<char>>(std::basic_istream<char,std::char_traits<char>> &,std::basic_string<char,std::char_traits<char>,std::allocator<char>> &,const _Elem)”的引用
        with
        [
            _Elem=char
        ]
[6/21] Building CXX object _deps\spdlog-build\CMakeFiles\spdlog.dir\src\color_sinks.cpp.obj
[7/21] Building CXX object _deps\spdlog-build\CMakeFiles\spdlog.dir\src\stdout_sinks.cpp.obj
[8/21] Building CXX object _deps\spdlog-build\CMakeFiles\spdlog.dir\src\fmt.cpp.obj
C:\Users\Listening\Documents\Workplace\cxClient\third_party\spdlog\include\spdlog/fmt/bundled/format-inl.h(2564): warning C4530: 使用了 C++ 异常处理程序,但未启用展开语义。请指定 /EHsc
[9/21] Building CXX object _deps\spdlog-build\CMakeFiles\spdlog.dir\src\spdlog.cpp.obj
C:\Users\Listening\Documents\Workplace\cxClient\third_party\spdlog\include\spdlog/logger-inl.h(185): warning C4530: 使用了 C++ 异常处理程序,但未启用展开语义。请指定 /EHsc
[10/21] Linking CXX static library _deps\spdlog-build\spdlogd.lib

I tried two versions (V1.11.0 and V1.10.0), but both had the same results. I don't know the reason

L-Super commented 1 year ago

I tried to change uint to uint_, it build successfully

template <typename Float>
constexpr auto exponent_mask() ->
    typename dragonbox::float_info<Float>::carrier_uint {
  using uint_ = typename dragonbox::float_info<Float>::carrier_uint;
  return ((uint_(1) << dragonbox::float_info<Float>::exponent_bits) - 1)
         << num_significand_bits<Float>();
}

image

tt4g commented 1 year ago

As far as the first error message is concerned, this is a problem that has already been resolved in the fmt library (not released). See: fmtlib/fmt#2809

However, the compiler reports warning C4459.

This is not a bug because you are handling compiler warnings as errors by the compile option /WX (C2220).

Remove the /WX option or add the /wd4459 option and ignore the warning. See: https://learn.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level?view=msvc-170

Or use pragma to suppress warning C4459.

#pragma warning(push)
#pragma warning(disable: 4459)
#include <spdlog/spdlog.h>
#pragma warning(pop)
L-Super commented 1 year ago

Thank you very much! I just found the answer too fmtlib/fmt#3137