HowardHinnant / date

A date and time library based on the C++11/14/17 <chrono> header
Other
3.16k stars 685 forks source link

`undefined symbol: SHGetKnownFolderPath`, when compile code with clang target=x86_64-pc-windows-msvc #440

Open denchat opened 5 years ago

denchat commented 5 years ago

I tried compile my code agaist tz.lib using clang target msvc.

lld-link: error: undefined symbol: SHGetKnownFolderPath
>>> referenced by tz.lib(tz.cpp.obj):(bool __cdecl date::remote_install(class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>> const
&))
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

Perhaps other than -lole32 (in documentation), now tz.lib also requires -lshell32 on windows? Is it just because that mingw64 automatically links agaist shell32.lib by default?

HowardHinnant commented 5 years ago

I'm not sure. I do see that SHGetKnownFolderPath is used in tz.cpp, and I note this comment:

// None of this happens with the MS SDK (at least VS14 which I tested), but: // Compiling with mingw, we get "error: 'KF_FLAG_DEFAULT' was not declared in this scope." // and error: 'SHGetKnownFolderPath' was not declared in this scope.". // It seems when using mingw NTDDI_VERSION is undefined and that // causes KNOWN_FOLDERFLAG and the KF flags to not get defined. // So we must define NTDDI_VERSION to get those flags on mingw. // The docs say though here: // https://msdn.microsoft.com/en-nz/library/windows/desktop/aa383745(v=vs.85).aspx // that "If you define NTDDI_VERSION, you must also define _WIN32_WINNT." // So we declare we require Vista or greater.

I don't have Windows to test on.

denchat commented 5 years ago

SHGetKnownFolderPath on this page https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/nf-shlobj_core-shgetknownfolderpath

SDK API requires: Vista defined in header: shlobj_core.h DLL: Shell32.dll (version 6.0.6000++)