gabime / spdlog

Fast C++ logging library.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Undefined symbol error for spdlog::details::os::utf8_to_strbuf on Windows

martingalvan-volue opened this issue · comments

Hi, I have the following code on Windows using spdlog 1.13.0 (as installed through vcpkg):

#include <spdlog/spdlog.h>
#include <spdlog/sinks/win_eventlog_sink.h>

int main()
{
    spdlog::sinks::win_eventlog_sink_mt sink("test");

    return 0;
}

I'm building using CMake, and defining SPDLOG_WCHAR_TO_UTF8_SUPPORT in my CMakeLists.txt. My program depends on the DLL (non-header-only) version of spdlog.

When trying to build this program, I get the following error:

[2/2] Linking CXX executable main.exe
FAILED: main.exe
C:\WINDOWS\system32\cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\main.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100226~1.0\x64\mt.exe --manifests  -- C:\PROGRA~1\MIB055~1\2022\PROFES~1\VC\Tools\MSVC\1440~1.338\bin\Hostx64\x64\link.exe /nologo CMakeFiles\main.dir\main.cpp.obj  /out:main.exe /implib:main.lib /pdb:main.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console  vcpkg_installed\x64-windows\debug\lib\spdlogd.lib  vcpkg_installed\x64-windows\debug\lib\fmtd.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && C:\WINDOWS\system32\cmd.exe /C "cd /D C:\Users\martin\spdlog_test\build && "C:\Program Files\PowerShell\7\pwsh.exe" -noprofile -executionpolicy Bypass -file C:/Users/martin/vcpkg/scripts/buildsystems/msbuild/applocal.ps1 -targetBinary C:/Users/martin/spdlog_test/build/main.exe -installedDir C:/Users/martin/spdlog_test/build/vcpkg_installed/x64-windows/debug/bin -OutVariable out""
LINK Pass 1: command "C:\PROGRA~1\MIB055~1\2022\PROFES~1\VC\Tools\MSVC\1440~1.338\bin\Hostx64\x64\link.exe /nologo CMakeFiles\main.dir\main.cpp.obj /out:main.exe /implib:main.lib /pdb:main.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console vcpkg_installed\x64-windows\debug\lib\spdlogd.lib vcpkg_installed\x64-windows\debug\lib\fmtd.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\main.dir/intermediate.manifest CMakeFiles\main.dir/manifest.res" failed (exit code 1120) with the following output:
main.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) void __cdecl spdlog::details::os::utf8_to_wstrbuf(class fmt::v10::basic_string_view<char>,class fmt::v10::basic_memory_buffer<wchar_t,250,class std::allocator<wchar_t> > &)" (__imp_?utf8_to_wstrbuf@os@details@spdlog@@YAXV?$basic_string_view@D@v10@fmt@@AEAV?$basic_memory_buffer@_W$0PK@V?$allocator@_W@std@@@56@@Z) referenced in function "protected: virtual void __cdecl spdlog::sinks::win_eventlog::win_eventlog_sink<class std::mutex>::sink_it_(struct spdlog::details::log_msg const &)" (?sink_it_@?$win_eventlog_sink@Vmutex@std@@@win_eventlog@sinks@spdlog@@MEAAXAEBUlog_msg@details@4@@Z)
main.exe : fatal error LNK1120: 1 unresolved externals
ninja: build stopped: subcommand failed.

However, if I make my program depend on spdlog::spdlog_header_only, it builds fine.

Am I missing some #include here?

Ah, nevermind. Turns out I hadn't enabled the wchar feature for spdlog on my vcpkg manifest. Adding that solved it:

{ "name": "spdlog", "features": [ "wchar" ] }