From 629d7b70d41095082bb7431e454c4eee95087f6b Mon Sep 17 00:00:00 2001
From: chrfranke <chrfranke@4ea69e1a-61f1-4043-bf83-b5c94c648137>
Date: Sat, 30 Apr 2022 16:01:22 +0000
Subject: [PATCH] Makefile.am: Windows: Ensure that advapi32 is linked before
 kernel32. This keeps backward compatibility with old versions of Windows if
 recent versions of MinGW-w64 are used.

git-svn-id: https://svn.code.sf.net/p/smartmontools/code/trunk@5369 4ea69e1a-61f1-4043-bf83-b5c94c648137
---
 smartmontools/ChangeLog   | 4 ++++
 smartmontools/Makefile.am | 6 ++++++
 2 files changed, 10 insertions(+)

diff --git a/smartmontools/ChangeLog b/smartmontools/ChangeLog
index fcef77210..ef376c9b5 100644
--- a/smartmontools/ChangeLog
+++ b/smartmontools/ChangeLog
@@ -2,6 +2,10 @@ $Id$
 
 2022-04-30  Christian Franke  <franke@computer.org>
 
+	Makefile.am: Windows: Ensure that advapi32 is linked before kernel32.
+	This keeps backward compatibility with old versions of Windows if
+	recent versions MinGW-w64 are used.
+
 	Makefile.am: config-vc: Remove HAVE___INT128 from generated config.h.
 
 	Makefile.am: Support 'svnversion' with CR/LF instead of LF output.
diff --git a/smartmontools/Makefile.am b/smartmontools/Makefile.am
index c70b0cb3a..06bad4ac0 100644
--- a/smartmontools/Makefile.am
+++ b/smartmontools/Makefile.am
@@ -282,6 +282,12 @@ smartd_SOURCES += \
 smartctl_LDADD += -lole32 -loleaut32
 smartd_LDADD   += -lole32 -loleaut32
 
+# Some versions of the MinGW-w64 import lib for kernel32.dll include some symbols
+# duplicated from advapi32.dll.  Older versions of windows provide these symbols
+# only in advapi32.dll.  Ensure that the advapi32 lib is linked first.
+smartctl_LDADD += -ladvapi32
+smartd_LDADD   += -ladvapi32
+
 endif
 
 if OS_SOLARIS
-- 
GitLab