在使用GDAL库版本1.9.1时,用VS2015编译出现了如下问题:
“fatal error C1189: #error: Macro definition of snprintf conflicts
with Standard Library function declaration”
可以在StackOverflow上找到对应问题:
VS 2015 compiling cocos2d-x 3.3 error “fatal error C1189: #error: Macro definition of snprintf conflicts with Standard Library function declaration”
提出的方法是,你得找到写有这个宏定义的头文件:
#define snprintf _snprintf
那么多头文件,不知道哪个里写了这句话,后来看了GDAL这个更新记录GDAL更新记录
终于发现这个宏定义在cpl_config.h中可以找到,将上面那段代码替换成下列代码就可以通过编译了:
#if defined(_MSC_VER) && (_MSC_VER < 1900)
# define snprintf _snprintf
#endif
这里_MSC_VER表示的是VS版本,1900对应VS2015,snprintf这个函数在VS2015中已经有了官方支持,所以原来的写法会重复定义。