weixin_39918128
weixin_39918128
2020-12-01 23:16

Narrowing conversion error on Windows.

Hello,

I'm trying out the library on Windows and it seems that I couldn't get it to work properly. Every time I try to compile the helloworld example, I got the error C2397: conversion from 'long' to 'uint64_t' requires a narrowing conversion at the BINLOG_INFO("Hello {}!", "World"); line.

However, when I compile the same code with WSL (GCC 8.3.0) everything works as expected, no warning at all. I also was able to build the helloworld example in the CMake generated project, and it ran just fine with the same VS.

I'm using Visual Studio 2019 on Windows 10.

I might be missing something obvious but I couldn't figure it out. Thank you so much for your time and help.

该提问来源于开源项目:Morgan-Stanley/binlog

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

7条回答

  • weixin_39955829 weixin_39955829 4月前

    Thanks. I take this was because of an incompatible set of MSVC flags, and there's no Binlog change needed to get this right - so I'm closing this issue. If you think otherwise, please reopen. Thanks for reporting!

    点赞 评论 复制链接分享
  • weixin_39955829 weixin_39955829 4月前

    Thanks for your feedback! GitHub provides Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.24.28314 in their CI, and binlog compiles there without error (example). What's your exact compiler version?

    Do you have a longer compiler error message or backtrace? Binlog itself does not use long at all (because of the platform differences like this), so I can't tell where the error is coming from.

    点赞 评论 复制链接分享
  • weixin_39918128 weixin_39918128 4月前

    Thank you for your prompt response. I'm using the latest Visual Studio (Version 16.4.5) and the same MSVC version as the CI (14.24.28314). The attached file is detailed build log I got from Visual Studio.

    Test_Binlog.log

    Thank you so much for your time and help.

    点赞 评论 复制链接分享
  • weixin_39955829 weixin_39955829 4月前

    Please also attach the full D:\Projects\Test_Binlog\Test_Binlog\Test_Binlog.cpp file.

    点赞 评论 复制链接分享
  • weixin_39918128 weixin_39918128 4月前

    GitHub does not allow to attach .cpp file so I renamed it to .txt here. Also it's just a simple helloworld just like in your instruction:

    
    #include <binlog>
    #include <fstream>
    #include <iostream>
    
    int main()
    {
        BINLOG_INFO("Hello {}!", "World");
    
        std::ofstream logfile("hello.blog", std::ofstream::out | std::ofstream::binary);
        binlog::consume(logfile);
    
        if (!logfile)
        {
            std::cerr << "Failed to write hello.blog\n";
            return 1;
        }
    
        std::cout << "Binary log written to hello.blog\n";
        return 0;
    }
    </iostream></fstream></binlog>

    Test_Binlog.txt

    Thank you so much for your time and help.

    点赞 评论 复制链接分享
  • weixin_39955829 weixin_39955829 4月前

    I'm unable to repro. Can you first preprocess the source file, and compile that directly? Perhaps that way MSVC will show the exact line the error happens on, and not just the macro that hides several lines.

    点赞 评论 复制链接分享
  • weixin_39918128 weixin_39918128 4月前

    I'm so sorry for the late reply. I turned on the Preprocess to a File and it was able to output the .i file just fine. The attached log is the output of that.

    Also, after looking around a little bit, it seems that the flag /ZI for Debug Information Format is the one causing problem. By default in Visual Studio console application project, it is set to Program Database for Edit And Continue (/ZI) in Debug mode. However, the project that CMake generated set that flag to None and in Release mode that flag is set to Program Database (/Zi), and both compiled just fine.

    So I switch it to /Zi in Debug mode and it works. No more error.

    Test_Binlog.log

    点赞 评论 复制链接分享