spdlog icon indicating copy to clipboard operation
spdlog copied to clipboard

Compiling errors/warnings VS2019

Open imamushroom opened this issue 6 years ago • 6 comments

When I've added the following headers to my solution I get a series of errors and warnings.

The header files I've added are:

#include "fmt/chrono.h"
#include "spdlog/spdlog.h"
#include "spdlog/sinks/rotating_file_sink.h"

I've also added the following definitions (as I've read other issues when compiling on VS2017 etc.)

#define NOMINMAX 
#define _SCL_SECURE_NO_WARNINGS

I'm not using <windows.h>

The errors and warning are as follows:

Severity	Code	Description	Project	File	Line	Suppression State
Warning	C26812	The enum type 'spdlog::details::padding_info::pad_side' is unscoped. Prefer 'enum class' over 'enum' (Enum.3).	mt4	C:\Users\andre\source\repos\HolyGrail2\mt4\spdlog_x86-windows\include\spdlog\pattern_formatter.h	33	
Warning	C26495	Variable 'fmt::v6::localtime::dispatcher::tm_' is uninitialized. Always initialize a member variable (type.6).	mt4	C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\chrono.h	322	
Warning	C26495	Variable 'fmt::v6::gmtime::dispatcher::tm_' is uninitialized. Always initialize a member variable (type.6).	mt4	C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\chrono.h	359	
Warning	C26812	The enum type 'fmt::v6::internal::char8_type' is unscoped. Prefer 'enum class' over 'enum' (Enum.3).	mt4	C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\format.h	517	
Warning	C26812	The enum type 'fmt::v6::align::type' is unscoped. Prefer 'enum class' over 'enum' (Enum.3).	mt4	C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\format.h	1051	
Warning	C26812	The enum type 'fmt::v6::sign::type' is unscoped. Prefer 'enum class' over 'enum' (Enum.3).	mt4	C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\format.h	1052	
Warning	C26495	Variable 'fmt::v6::internal::basic_writer<fmt::v6::buffer_range<char> >::int_writer<__int64,fmt::v6::basic_format_specs<char> >::prefix' is uninitialized. Always initialize a member variable (type.6).	mt4	C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\format.h	1493	
Warning	C26495	Variable 'fmt::v6::internal::basic_writer<fmt::v6::buffer_range<char> >::int_writer<char,fmt::v6::basic_format_specs<char> >::prefix' is uninitialized. Always initialize a member variable (type.6).	mt4	C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\format.h	1493	
Warning	C26495	Variable 'fmt::v6::internal::basic_writer<fmt::v6::buffer_range<char> >::int_writer<int,fmt::v6::basic_format_specs<char> >::prefix' is uninitialized. Always initialize a member variable (type.6).	mt4	C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\format.h	1493	
Warning	C26495	Variable 'fmt::v6::internal::basic_writer<fmt::v6::buffer_range<char> >::int_writer<unsigned __int64,fmt::v6::basic_format_specs<char> >::prefix' is uninitialized. Always initialize a member variable (type.6).	mt4	C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\format.h	1493	
Warning	C26495	Variable 'fmt::v6::internal::basic_writer<fmt::v6::buffer_range<char> >::int_writer<unsigned int,fmt::v6::basic_format_specs<char> >::prefix' is uninitialized. Always initialize a member variable (type.6).	mt4	C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\format.h	1493	
Warning	C26495	Variable 'fmt::v6::localtime::dispatcher::tm_' is uninitialized. Always initialize a member variable (type.6).	mt4	C:\Users\andre\source\repos\HolyGrail2\mt4\spdlog\include\spdlog\fmt\bundled\chrono.h	322	
Warning	C26495	Variable 'fmt::v6::gmtime::dispatcher::tm_' is uninitialized. Always initialize a member variable (type.6).	mt4	C:\Users\andre\source\repos\HolyGrail2\mt4\spdlog\include\spdlog\fmt\bundled\chrono.h	359	
Warning	C26812	The enum type 'spdlog::level::level_enum' is unscoped. Prefer 'enum class' over 'enum' (Enum.3).	mt4	C:\Users\andre\source\repos\HolyGrail2\mt4\spdlog_x86-windows\include\spdlog\common-inl.h	16	
Warning	C6387	'f' could be '0':  this does not adhere to the specification for the function '_fileno'. 	mt4	C:\Users\andre\source\repos\HolyGrail2\mt4\spdlog_x86-windows\include\spdlog\details\os-inl.h	210	
Severity	Code	Description	Project	File	Line	Suppression State
Error	C2589	'(': illegal token on right side of '::'	mt4	C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\chrono.h	51	
Error	C2589	'(': illegal token on right side of '::'	mt4	C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\chrono.h	87	
Error	C2760	syntax error: unexpected token '(', expected ')'	mt4	C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\chrono.h	87	
Error	C2589	'(': illegal token on right side of '::'	mt4	C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\chrono.h	144	
Error	C2589	'(': illegal token on right side of '::'	mt4	C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\chrono.h	203	
Severity	Code	Description	Project	File	Line	Suppression State
Warning	C4003	not enough arguments for function-like macro invocation 'min'	mt4	C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\chrono.h	203	
Warning	C4003	not enough arguments for function-like macro invocation 'min'	mt4	C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\chrono.h	51	
Warning	C4003	not enough arguments for function-like macro invocation 'max'	mt4	C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\chrono.h	51	
Warning	C4003	not enough arguments for function-like macro invocation 'max'	mt4	C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\chrono.h	87	
Warning	C4003	not enough arguments for function-like macro invocation 'max'	mt4	C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\chrono.h	100	
Warning	C4003	not enough arguments for function-like macro invocation 'max'	mt4	C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\chrono.h	144		

I believe the line causing the issue is this line:

spdlog::debug("utc_tm = {0:%F_%T}, utc_open = {1:%F_%T}, utc_close = {2:%F_%T}", utc_tm, utc_open, utc_close);

Where:

tm utc_tm = *gmtime(&t);
tm utc_open = *gmtime(&m_mkt_open_time);
tm utc_close = `*gmtime(&m_mkt_close_time);`

I'm not an expert in C++ so would like to know how I fix these errors.

Thanks.

imamushroom avatar Sep 05 '20 17:09 imamushroom

windows.h is used inside spdlog and fmt. They define a NOMINMAX macro to suppress min() and max() expansion. However, you seem to be including the headers in a way that the library doesn't expect.

fmt library is bundled in spdlog project. As far as I see your snippet, you are using external fmt library.

If you want to use external fmt, the CMake variable SPDLOG_FMT_EXTERNAL should be defined when buildling CMake.

https://github.com/gabime/spdlog/blob/4a9ccf7e38e257feecce0c579a782741254eaeef/CMakeLists.txt#L78-L79

Also, SPDLOG_FMT_EXTERNAL macro should be defined at compile time.

https://github.com/gabime/spdlog/blob/4a9ccf7e38e257feecce0c579a782741254eaeef/include/spdlog/fmt/fmt.h#L13

tt4g avatar Sep 05 '20 23:09 tt4g

Thanks for your message.

I'm not bothered if the fmt/chrono.h file is external or internal so I removed the definition and removed the debug statement with the tm conversion. It compiles without any errors but 36 warnings. Here are the warnings.

Severity Code Description Project File Line Suppression State Warning C26495 Variable 'fmt::v6::localtime::dispatcher::tm_' is uninitialized. Always initialize a member variable (type.6). mt4 C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\chrono.h 322 Warning C26495 Variable 'fmt::v6::gmtime::dispatcher::tm_' is uninitialized. Always initialize a member variable (type.6). mt4 C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\chrono.h 359 Warning C26812 The enum type 'fmt::v6::internal::char8_type' is unscoped. Prefer 'enum class' over 'enum' (Enum.3). mt4 C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\format.h 517 Warning C26812 The enum type 'fmt::v6::align::type' is unscoped. Prefer 'enum class' over 'enum' (Enum.3). mt4 C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\format.h 1051 Warning C26812 The enum type 'fmt::v6::sign::type' is unscoped. Prefer 'enum class' over 'enum' (Enum.3). mt4 C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\format.h 1052 Warning C26495 Variable 'fmt::v6::internal::basic_writer<fmt::v6::buffer_range<char> >::int_writer<__int64,fmt::v6::basic_format_specs<char> >::prefix' is uninitialized. Always initialize a member variable (type.6). mt4 C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\format.h 1493 Warning C26495 Variable 'fmt::v6::internal::basic_writer<fmt::v6::buffer_range<char> >::int_writer<char,fmt::v6::basic_format_specs<char> >::prefix' is uninitialized. Always initialize a member variable (type.6). mt4 C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\format.h 1493 Warning C26495 Variable 'fmt::v6::internal::basic_writer<fmt::v6::buffer_range<char> >::int_writer<int,fmt::v6::basic_format_specs<char> >::prefix' is uninitialized. Always initialize a member variable (type.6). mt4 C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\format.h 1493 Warning C26495 Variable 'fmt::v6::internal::basic_writer<fmt::v6::buffer_range<char> >::int_writer<unsigned __int64,fmt::v6::basic_format_specs<char> >::prefix' is uninitialized. Always initialize a member variable (type.6). mt4 C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\format.h 1493 Warning C26495 Variable 'fmt::v6::internal::basic_writer<fmt::v6::buffer_range<char> >::int_writer<unsigned int,fmt::v6::basic_format_specs<char> >::prefix' is uninitialized. Always initialize a member variable (type.6). mt4 C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\format.h 1493 Warning C26495 Variable 'fmt::v6::localtime::dispatcher::tm_' is uninitialized. Always initialize a member variable (type.6). mt4 C:\Users\andre\source\repos\HolyGrail2\mt4\spdlog\include\spdlog\fmt\bundled\chrono.h 322 Warning C26495 Variable 'fmt::v6::gmtime::dispatcher::tm_' is uninitialized. Always initialize a member variable (type.6). mt4 C:\Users\andre\source\repos\HolyGrail2\mt4\spdlog\include\spdlog\fmt\bundled\chrono.h 359 Warning C26812 The enum type 'spdlog::level::level_enum' is unscoped. Prefer 'enum class' over 'enum' (Enum.3). mt4 C:\Users\andre\source\repos\HolyGrail2\mt4\spdlog_x86-windows\include\spdlog\common-inl.h 16 Warning C6387 'f' could be '0': this does not adhere to the specification for the function '_fileno'. mt4 C:\Users\andre\source\repos\HolyGrail2\mt4\spdlog_x86-windows\include\spdlog\details\os-inl.h 210 Warning C26812 The enum type 'spdlog::details::padding_info::pad_side' is unscoped. Prefer 'enum class' over 'enum' (Enum.3). mt4 C:\Users\andre\source\repos\HolyGrail2\mt4\spdlog_x86-windows\include\spdlog\pattern_formatter.h 33 Warning C26495 Variable 'State::m_working_times' is uninitialized. Always initialize a member variable (type.6). mt4 C:\Users\andre\source\repos\HolyGrail2\mt4\State.cpp 3

Incidentally, I had to build spdlog using the vcpkg install procedure as the standard cmake/make build did not work for me. The make -j command does not have any targets and no makefile was generated from the cmake .. process. This could do with changing with a clear example as I'm not an expert with cmake and/or make.

After all the warnings are resolved I need an example of how to convert to a tm type as per the example debug statement I give in the original post as if I include this line, an additional error is generated, which is:

Severity Code Description Project File Line Suppression State Error C2338 Cannot format argument. To make type T formattable provide a formatter<T> specialization: https://fmt.dev/latest/api.html#formatting-user-defined-types mt4 C:\Users\andre\source\repos\HolyGrail2\mt4\fmt_x86-windows\include\fmt\core.h 1017

Edit: I've got around this problem by using the time_t type instead so ignore the tm debug message part as it is no longer relevant - sorry for the inconvenience.

Thanks in advance for your assistance.

imamushroom avatar Sep 06 '20 02:09 imamushroom

If you are installing spdlog with vcpkg, it is recommended that you open the issue in the vcpkg repository.

And if you can't build as a result of modifying the fmt source, that's not a problem with spdlog. spdlog supports fmt bundled with external fmt, but the The use of fmt with your own modifications is at your own risk.

tt4g avatar Sep 06 '20 03:09 tt4g

vcpkg provides fmt library. Did you install fmt with vcpkg?

tt4g avatar Sep 06 '20 06:09 tt4g

vcpkg provides fmt library. Did you install fmt with vcpkg?

Yes, it was automatic.

imamushroom avatar Sep 07 '20 18:09 imamushroom

If you are installing spdlog with vcpkg, it is recommended that you open the issue in the vcpkg repository.

And if you can't build as a result of modifying the fmt source, that's not a problem with spdlog. spdlog supports fmt bundled with external fmt, but the The use of fmt with your own modifications is at your own risk.

Ok, I'll open a case in the vcpkg tree although I still think it's native spdlog issues on Windows.

Thanks.

imamushroom avatar Sep 07 '20 18:09 imamushroom