ImageMagick / ImageMagick

🧙‍♂️ ImageMagick 7
https://imagemagick.org
Other
12.23k stars 1.36k forks source link

min()/max() builder error on windows #7542

Closed wuxinmao2008 closed 3 months ago

wuxinmao2008 commented 3 months ago

ImageMagick version

7.1.1-36

Operating system

Windows

Operating system, version and so on

Windows11, VS 2022, Windows SDK 10.0.19041

Description

I meet such errors

C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\GdiplusTypes.h(479,22): error C3861: “min”: 找不到标识符
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\GdiplusTypes.h(480,23): error C3861: “min”: 找不到标识符
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\GdiplusTypes.h(481,21): error C3861: “max”: 找不到标识符
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\GdiplusTypes.h(482,20): error C3861: “max”: 找不到标识符
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\GdiplusTypes.h(503,22): error C3861: “max”: 找不到标识符
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\GdiplusTypes.h(504,23): error C3861: “max”: 找不到标识符
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\GdiplusTypes.h(505,21): error C3861: “min”: 找不到标识符
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\GdiplusTypes.h(506,20): error C3861: “min”: 找不到标识符
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\GdiplusTypes.h(667,21): error C3861: “min”: 找不到标识符
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\GdiplusTypes.h(668,22): error C3861: “min”: 找不到标识符
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\GdiplusTypes.h(669,20): error C3861: “max”: 找不到标识符
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\GdiplusTypes.h(670,19): error C3861: “max”: 找不到标识符
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\GdiplusTypes.h(691,21): error C3861: “max”: 找不到标识符
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\GdiplusTypes.h(692,22): error C3861: “max”: 找不到标识符
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\GdiplusTypes.h(693,20): error C3861: “min”: 找不到标识符
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\GdiplusTypes.h(694,19): error C3861: “min”: 找不到标识符

Finnally , i found this was cause by coders/emf.c which includes "" I soveld this by following instruction by possible-problems-with-nominmax-on-visual-c

Steps to Reproduce

I Add A patch below.

wuxinmao2008 commented 3 months ago
From 2abeff921070a7841444b1bd2df673d2a6089c72 Mon Sep 17 00:00:00 2001
From: wuxinmao2008 <wuxinmao2008@hotmail.com>
Date: Fri, 9 Aug 2024 11:26:01 +0800
Subject: [PATCH] fix min/max error in GdiplusTypes.h

---
 coders/emf.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/coders/emf.c b/coders/emf.c
index ff611e839..08782c0a6 100644
--- a/coders/emf.c
+++ b/coders/emf.c
@@ -49,6 +49,13 @@
 #    endif
 #  else
 #pragma warning(disable: 4458)
+#    define NOMINMAX
+#    include <algorithm>
+namespace Gdiplus
+{
+  using std::min;
+  using std::max;
+}
 #    include <gdiplus.h>
 #pragma warning(default: 4458)
 #    pragma comment(lib, "gdiplus.lib")
-- 
2.45.2.windows.1
dlemstra commented 3 months ago

You should switch to a newer version of the SDK instead. This issue has been fixed by Microsoft: https://developercommunity.visualstudio.com/t/GdiplusTypesh-does-not-compile-with-NOM/727770