From 8bf8cf4aaeb296681321f82c26019430787834a7 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 8 Dec 2020 16:43:33 +0100 Subject: [PATCH] Fix link error due to StrCmpLogicalW() when using MSVC Add the #pragma to link with shlwapi in the same object file which uses this function, as even though the same pragma was already present in other files, they could be completely discarded by the linker resulting in link errors about unresolved StrCmpLogicalW() later. Also move the MinGW-specific function declaration to the top of the file, near the inclusion of the header which would normally declare it. --- src/common/arrstr.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/common/arrstr.cpp b/src/common/arrstr.cpp index 45262b2dce..dc569a80bf 100644 --- a/src/common/arrstr.cpp +++ b/src/common/arrstr.cpp @@ -27,8 +27,20 @@ #if defined( __WINDOWS__ ) #include -#endif + // In some distributions of MinGW32, this function is exported in the library, + // but not declared in shlwapi.h. Therefore we declare it here. + #if defined( __MINGW32_TOOLCHAIN__ ) + extern "C" __declspec(dllimport) int WINAPI StrCmpLogicalW(LPCWSTR psz1, LPCWSTR psz2); + #endif + + // For MSVC we can also link the library containing StrCmpLogicalW() + // directly from here, for the other compilers this needs to be done at + // makefiles level. + #ifdef __VISUALC__ + #pragma comment(lib, "shlwapi") + #endif +#endif // ============================================================================ // ArrayString @@ -892,17 +904,6 @@ int wxCMPFUNC_CONV wxCmpNaturalGeneric(const wxString& s1, const wxString& s2) return comparison; } -// ---------------------------------------------------------------------------- -// Declaration of StrCmpLogicalW() -// ---------------------------------------------------------------------------- -// -// In some distributions of MinGW32, this function is exported in the library, -// but not declared in shlwapi.h. Therefore we declare it here. -#if defined( __MINGW32_TOOLCHAIN__ ) - extern "C" __declspec(dllimport) int WINAPI StrCmpLogicalW(LPCWSTR psz1, LPCWSTR psz2); -#endif - - // ---------------------------------------------------------------------------- // wxCmpNatural // ----------------------------------------------------------------------------