Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Compilation error with external spdlog on Windows #1147

Open
jeydi0421 opened this issue Jan 2, 2025 · 0 comments
Open

Compilation error with external spdlog on Windows #1147

jeydi0421 opened this issue Jan 2, 2025 · 0 comments
Assignees

Comments

@jeydi0421
Copy link

jeydi0421 commented Jan 2, 2025

Describe the bug
When trying to compile the library with an external version of spdlog with a certain configuration, there is a misuse of the spdlog API which makes it not compile on Windows. The following errors occur while compiling:

D:\lief\src\0.16.1-a11c893c52.clean\src\logging.cpp(48): error C2672: 'spdlog::basic_logger_mt': no matching overloaded function found
D:\vcpkg_installed\x64-windows-static\include\spdlog/sinks/basic_file_sink.h(44): note: could be 'std::shared_ptr<spdlog::logger> spdlog::basic_logger_mt(const std::string &,const spdlog::filename_t &,bool,const spdlog::file_event_handlers &)'
D:\lief\src\0.16.1-a11c893c52.clean\src\logging.cpp(48): note: 'initializing': cannot convert from 'const std::string' to 'const spdlog::filename_t &'
D:\lief\src\0.16.1-a11c893c52.clean\src\logging.cpp(48): note: Reason: cannot convert from 'const std::string' to 'const spdlog::filename_t'
D:\lief\src\0.16.1-a11c893c52.clean\src\logging.cpp(48): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
D:\lief\src\0.16.1-a11c893c52.clean\src\logging.cpp(108): error C2672: 'spdlog::basic_logger_mt': no matching overloaded function found
D:\vcpkg_installed\x64-windows-static\include\spdlog/sinks/basic_file_sink.h(44): note: could be 'std::shared_ptr<spdlog::logger> spdlog::basic_logger_mt(const std::string &,const spdlog::filename_t &,bool,const spdlog::file_event_handlers &)'
D:\lief\src\0.16.1-a11c893c52.clean\src\logging.cpp(108): note: 'initializing': cannot convert from 'const std::string' to 'const spdlog::filename_t &'
D:\lief\src\0.16.1-a11c893c52.clean\src\logging.cpp(108): note: Reason: cannot convert from 'const std::string' to 'const spdlog::filename_t'
D:\lief\src\0.16.1-a11c893c52.clean\src\logging.cpp(108): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
D:\lief\src\0.16.1-a11c893c52.clean\src\logging.cpp(109): error C3536: 'logger': cannot be used before it is initialized
D:\lief\src\0.16.1-a11c893c52.clean\src\logging.cpp(109): error C2664: 'void LIEF::logging::Logger::set_logger(std::shared_ptr<spdlog::logger>)': cannot convert argument 1 from 'int' to 'std::shared_ptr<spdlog::logger>'
D:\lief\src\0.16.1-a11c893c52.clean\src\logging.cpp(109): note: 'std::shared_ptr<spdlog::logger>::shared_ptr': no overloaded function could convert all the argument types
include\memory(1573): note: could be 'std::shared_ptr<spdlog::logger>::shared_ptr(std::nullptr_t) noexcept'
D:\lief\src\0.16.1-a11c893c52.clean\src\logging.cpp(109): note: 'std::shared_ptr<spdlog::logger>::shared_ptr(std::nullptr_t) noexcept': cannot convert argument 1 from 'int' to 'std::nullptr_t'
D:\lief\src\0.16.1-a11c893c52.clean\src\logging.cpp(109): note: only a null pointer constant can be converted to nullptr_t
include\memory(1668): note: or       'std::shared_ptr<spdlog::logger>::shared_ptr(std::unique_ptr<_Ux,_Dx> &&)'
include\memory(1644): note: or       'std::shared_ptr<spdlog::logger>::shared_ptr(std::shared_ptr<_Ty2> &&) noexcept'
include\memory(1634): note: or       'std::shared_ptr<spdlog::logger>::shared_ptr(const std::shared_ptr<_Ty2> &) noexcept'
include\memory(1624): note: or       'std::shared_ptr<spdlog::logger>::shared_ptr(std::shared_ptr<_Ty2> &&,spdlog::logger *) noexcept'
include\memory(1618): note: or       'std::shared_ptr<spdlog::logger>::shared_ptr(const std::shared_ptr<_Ty2> &,spdlog::logger *) noexcept'
include\memory(1613): note: or       'std::shared_ptr<spdlog::logger>::shared_ptr(std::nullptr_t,_Dx,_Alloc)'
include\memory(1607): note: or       'std::shared_ptr<spdlog::logger>::shared_ptr(std::nullptr_t,_Dx)'
include\memory(1601): note: or       'std::shared_ptr<spdlog::logger>::shared_ptr(_Ux *,_Dx,_Alloc)'
include\memory(1593): note: or       'std::shared_ptr<spdlog::logger>::shared_ptr(_Ux *,_Dx)'
D:\lief\src\0.16.1-a11c893c52.clean\src\logging.cpp(109): note: while trying to match the argument list '(int)'
D:\lief\src\0.16.1-a11c893c52.clean\src\logging.hpp(120): note: see declaration of 'LIEF::logging::Logger::set_logger'
D:\lief\src\0.16.1-a11c893c52.clean\src\logging.cpp(109): note: while trying to match the argument list '(int)'

To Reproduce
Add an external version of spdlog and configure it to define SPDLOG_WCHAR_FILENAMES. This is the only way to correctly handle unicode paths on Windows. Now compile LIEF and see it fail when trying to create a logger through the spdlog::basic_logger_mt interface like here:

sink = spdlog::basic_logger_mt(name, filepath, truncate);

The issue is that you pass a std::string to the logging interface which expects a spdlog::filename_t.
Same issue also happens in
auto logger = spdlog::basic_logger_mt(DEFAULT_NAME, path, /*truncate=*/true);

Expected behavior
I expect the library to build fine on Windows even with an external spdlog using SPDLOG_WCHAR_FILENAMES define.

Environment (please complete the following information):

  • System and Version : Windows 10 x64
  • Target format: Any
  • LIEF commit version: Version 0.16.1, 564b5e3

Additional context
None

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants