sharkdp/dbg-macro

Windows Supported?

dry11orange opened this issue · 14 comments

Windows Supported?

Yes

I got an error

  • cmake build with vs2015
  • dbg-macro\dbg.h(473): error C2912: 显式专用化;“bool dbg::pretty_print(std::ostream &,const dbg::time &)”不是函数模板的专用化

could you please post the full error output?

error 0:

1>------ 已启动生成: 项目: dbg_macro-example, 配置: Debug Win32 ------
1> example.cpp
1>D:\user_root\code\github\waiting\dbg-macro\dbg.h : warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失
1>D:\user_root\code\github\waiting\dbg-macro\dbg.h(68): fatal error C1083: 无法打开包括文件: “optional”: No such file or directory
========== 生成: 成功 0 个,失败 1 个,最新 1 个,跳过 0 个 ==========

then I did this:

#if __cplusplus >= 201703L || defined(_MSC_VER) ====>>> #if __cplusplus >= 201703L && defined(_MSC_VER)

and got error 1:

1>------ 已启动生成: 项目: dbg_macro-example, 配置: Debug Win32 ------
1> example.cpp
1>D:\user_root\code\github\waiting\dbg-macro\dbg.h : warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失
1>D:\user_root\code\github\waiting\dbg-macro\dbg.h(473): error C2912: 显式专用化;“bool dbg::pretty_print(std::ostream &,const dbg::time &)”不是函数模板的专用化
1>D:\user_root\code\github\waiting\dbg-macro\dbg.h(468): warning C4996: 'localtime': This function or variable may be unsafe. Consider using localtime_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\time.h(505): note: 参见“localtime”的声明
========== 生成: 成功 0 个,失败 1 个,最新 1 个,跳过 0 个 ==========

Do not modify the dbg.h file. Instead, specify the C++ standard to be at least C++11. What are you using currently?

vs2015


And I try vs2017,vs2019
error as follow:

已启动生成…
1>------ 已启动生成: 项目: dbg_macro-example, 配置: Debug Win32 ------
1>Building Custom Rule D:/user_root/code/github/waiting/dbg-macro/CMakeLists.txt
1>example.cpp
1>d:\user_root\code\github\waiting\dbg-macro\dbg.h : warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失
1>class template optional is only available with C++17 or later.
1>class template variant is only available with C++17 or later.
1>d:\user_root\code\github\waiting\dbg-macro\dbg.h(468): warning C4996: 'localtime': This function or variable may be unsafe. Consider using localtime_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>c:\program files (x86)\windows kits\10\include\10.0.10240.0\ucrt\time.h(505): note: 参见“localtime”的声明
1>d:\user_root\code\github\waiting\dbg-macro\dbg.h(564): error C2039: “string_view”: 不是“std”的成员
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.16.27023\include\vector(20): note: 参见“std”的声明
1>d:\user_root\code\github\waiting\dbg-macro\dbg.h(564): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>d:\user_root\code\github\waiting\dbg-macro\dbg.h(564): error C2143: 语法错误: 缺少“,”(在“&”的前面)
1>d:\user_root\code\github\waiting\dbg-macro\dbg.h(565): error C2065: “value”: 未声明的标识符
1>d:\user_root\code\github\waiting\dbg-macro\dbg.h(584): error C2039: “optional”: 不是“std”的成员
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.16.27023\include\vector(20): note: 参见“std”的声明
1>d:\user_root\code\github\waiting\dbg-macro\dbg.h(584): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>d:\user_root\code\github\waiting\dbg-macro\dbg.h(584): error C2988: 不可识别的模板声明/定义
1>d:\user_root\code\github\waiting\dbg-macro\dbg.h(584): error C2143: 语法错误: 缺少“,”(在“<”的前面)
1>d:\user_root\code\github\waiting\dbg-macro\dbg.h(598): error C2039: “variant”: 不是“std”的成员
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.16.27023\include\vector(20): note: 参见“std”的声明
1>d:\user_root\code\github\waiting\dbg-macro\dbg.h(598): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>d:\user_root\code\github\waiting\dbg-macro\dbg.h(598): error C2988: 不可识别的模板声明/定义
1>d:\user_root\code\github\waiting\dbg-macro\dbg.h(598): error C2143: 语法错误: 缺少“,”(在“<”的前面)
1>已完成生成项目“dbg_macro-example.vcxproj”的操作 - 失败。
========== 生成: 成功 0 个,失败 1 个,最新 1 个,跳过 0 个 ==========

How do you run cmake?

In the CI run, we use:

cmake .. -DCMAKE_CXX_STANDARD=17 -DCMAKE_TOOLCHAIN_FILE=c:/tools/vcpkg/scripts/buildsystems/vcpkg.cmake

There might indeed be an error in the section you tried to modify:

#if __cplusplus >= 201703L || defined(_MSC_VER)
#define DBG_MACRO_CXX_STANDARD 17
#elif __cplusplus >= 201402L
#define DBG_MACRO_CXX_STANDARD 14
#else
#define DBG_MACRO_CXX_STANDARD 11
#endif
  • I have modify it back to source
  • And I use cmake-gui to build

now I want to coding with vs2015

  1. Create a project empty
  2. copy dbg.h and example.cpp to this project path
  3. build error!

What else should I do?

error info:

1>------ 已启动生成: 项目: test_dbg, 配置: Debug Win32 ------
1> example.cpp
1>c:\users\administrator\documents\visual studio 2015\projects\test_dbg\test_dbg\dbg.h : warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失
1>CL : warning : the 'dbg.h' header is included in your code base
1>c:\users\administrator\documents\visual studio 2015\projects\test_dbg\test_dbg\dbg.h(68): fatal error C1083: 无法打开包括文件: “optional”: No such file or directory
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========

I try this on raspberry:
It's simple and valid

root@raspberrypi:~/github/dbg_macro/dbg-macro# ls
appveyor.yml  build  CMakeLists.txt  dbg.h  LICENSE  README.md  tests
root@raspberrypi:~/github/dbg_macro/dbg-macro# mkdir simple_test
root@raspberrypi:~/github/dbg_macro/dbg-macro# cp dbg.h tests/example.cpp ./simple_test/
root@raspberrypi:~/github/dbg_macro/dbg-macro# cd simple_test/
root@raspberrypi:~/github/dbg_macro/dbg-macro/simple_test# ls
dbg.h  example.cpp
root@raspberrypi:~/github/dbg_macro/dbg-macro/simple_test# nano example.cpp
root@raspberrypi:~/github/dbg_macro/dbg-macro/simple_test# //modify <dbg.h>   ->   "dbg.h"^C
root@raspberrypi:~/github/dbg_macro/dbg-macro/simple_test# g++ example.cpp
In file included from example.cpp:1:
dbg.h:39:76: note: #pragma message: WARNING: the 'dbg.h' header is included in your code base
 #pragma message("WARNING: the 'dbg.h' header is included in your code base")
                                                                            ^
root@raspberrypi:~/github/dbg_macro/dbg-macro/simple_test# ls
a.out  dbg.h  example.cpp
root@raspberrypi:~/github/dbg_macro/dbg-macro/simple_test# ./a.out
[example.cpp:15 (main)] message = "hello" (std::string)
[example.cpp:19 (main)] 3 * a = 6 (int)
[example.cpp:22 (main)] numbers = {7, 13, 42} (std::vector<int>)
[example.cpp:25 (main)] this line is executed
[example.cpp:6 (factorial)] n <= 1 = false (bool)
[example.cpp:6 (factorial)] n <= 1 = false (bool)
[example.cpp:6 (factorial)] n <= 1 = false (bool)
[example.cpp:6 (factorial)] n <= 1 = true (bool)
[example.cpp:7 (factorial)] 1 = 1 (int)
[example.cpp:9 (factorial)] n * factorial(n - 1) = 2 (int)
[example.cpp:9 (factorial)] n * factorial(n - 1) = 6 (int)
[example.cpp:9 (factorial)] n * factorial(n - 1) = 24 (int)
root@raspberrypi:~/github/dbg_macro/dbg-macro/simple_test#

I have updated our CI system to properly run tests on Windows for C++14 and C++17. I have also fixed the problematic line in dbg.h. Could you please try again with the latest version of dbg.h?

  • build with vs2017 and vs2019, OK
  • build with vs2015, same old
    • C++11, give up?

I think I can reproduce the error here: https://godbolt.org/z/8Ydj35

error C2912: explicit specialization 'bool dbg::pretty_print(std::ostream &,const dbg::time &)' is not a specialization of a function template

Unfortunately, even if I fix that, there seem to be a number of other errors. I don't know how to test MSVC 2015 on GitHub Actions. If we don't have CI support for it, I don't really want to maintain it. But I'm happy for any help if someone wants to fix this.

C++11 is not the problem (it works fine with GCC and Clang). It's a problem with MSVC 2015.

dbg.h(759,1): error C3523: “sizeof...”要求一个未扩展的参数包作为其参数
win10 x64 vs2019 CXX14