fatal error C1189: #error: "Oops: min() and/or max() are defined as preprocessor macros. Define NOMINMAX macro before including any system headers!"

1.问题描述

vs2015 使用pg数据库的C++库文件4.0.1版本libpqxx.dll,包含头文件#include "pqxxpqxx" 出现这个错误:

fatal error C1189: #error:  "Oops: min() and/or max() are defined as preprocessor macros.  Define NOMINMAX macro before including any system headers!"

2.原因分析

图1 pqxx头文件中的定义

(1)如上图1所示,pqxx的头文件中compiler-public.hxx中有一段,如果定义了min和max,则会抛出错误。系统头文件中定义了这两个宏min和max。所以如果把pqxx包含在系统头文件之后,就会出现这个错误。所以要求吧pqxx包含在系统头文件之前。这样就不会抛出异常。

fatal error C1189: #error:  "Oops: min() and/or max() are defined as preprocessor macros.  Define NOMINMAX macro before including any system headers!"

pqxx文件定义了一些宏定义,与系统中的系统头文件的宏定义冲突,导致系统头文件编译时抛出错误;

(2)当你把pqxx包含在系统头文件之前又会出现系统头文件中找不到min和max标识符的错误,原因是图1中定义了NOMINMAX宏,使得系统头文件中的min和max无效了。

1>c:program files (x86)windows kits8.1includeumGdiplusTypes.h(475): error C3861: “min”: 找不到标识符
1>c:program files (x86)windows kits8.1includeumGdiplusTypes.h(476): error C3861: “min”: 找不到标识符
1>c:program files (x86)windows kits8.1includeumGdiplusTypes.h(477): error C3861: “max”: 找不到标识符
1>c:program files (x86)windows kits8.1includeumGdiplusTypes.h(478): error C3861: “max”: 找不到标识符
1>c:program files (x86)windows kits8.1includeumGdiplusTypes.h(499): error C3861: “max”: 找不到标识符

(3)所以pqxx的头文件中没有定义min和max,也不需要min和max宏。和系统头文件中定义了min和max宏,也需要min和max宏。

3.解决办法

在stdafx.h头文件的最前面加上如下,先包含pqxx,放在系统头文件前面,中间取消NOMINMAX的宏定义,使得系统头文件中的min和max宏生效,再包含系统头文件,系统头文件中就可以使用min和max。

#include "pqxxpqxx"
using namespace pqxx;
#undef NOMINMAX

自己开发了一个股票智能分析软件,功能很强大,需要的点击下面的链接获取:

https://www.cnblogs.com/bclshuai/p/11380657.html

百度云盘下载地址:

链接:https://pan.baidu.com/s/1swkQzCIKI3g3ObcebgpIDg

提取码:mc8l

微信公众号获取最新的软件和视频介绍

QStockView

原文地址:https://www.cnblogs.com/bclshuai/p/11097547.html