FreeImage 3.17.0 在VS2015下编译及遇到问题解决
2017-07-08 10:20
537 查看
1、在FreeImage 3170版本中,里面没有带VS2015的工程文件。但是有VS2005/2008/2013的。双击源代码目录下面的FreeImage.2013.sln文件,然后VS2015就会弹出升级编译器和库选项。
2、选择要编译的版本为win32还是X64,然后编辑库文件。编译完成后会出现“fatal error C1189: #error: Macro definition of snprintf conflicts with Standard Library function declaration”的错误。
这时候需要修改源码中的tif_config.h文件。该文件在源码目录中只有一个,因此找到之后直接修改即可。将源码中的
#ifdef _WIN32
#define
snprintf _snprintf // 将此行注释掉
#define
lfind _lfind
#endif
// _WIN32
修改为:
#ifdef _WIN32//#define snprintf _snprintf#define
lfind _lfind#endif // _WIN32
这是因为在早期的VC自带的C标准库中确实没有snprintf这个函数,只有_snprintf。但是VS2015下是有的,所以这里不注释掉会有重定义的问题。
也可以修改为:
#ifdef
_WIN32
#if
defined(_MSC_VER) && _MSC_VER < 1900
#define
snprintf _snprintf
#endif
#define
lfind _lfind
#endif
// _WIN32
3、再次进行编译,编译完成后可以到源码目录下的Dist目录拷贝FreeImage.h和库文件。
错误原因分析:
目前,在很多的库和程序中使用函数通过定义函数_snprintf()的方式来使用snprintf(),因为系统中已经定义好了_snprintf()函数。
#define snprintf _snprintf
最终,Visual Studio 14 中开始定义了snprintf()!
既然在编译器中开始支持snprintf()函数,因此,我们无需进行重定义(画蛇添足)。定义这个函数就会造成overshadow已经在stdio.h中定义的snprintf()。为了约束用户的这种方式,系统在 stdio.h文件中添加了如下的提示:
#ifdef snprintf
#error: Macro definition of snprintf conflicts
with Standard Library function declaration”
#endif
因此,就会造成上面不编译不成功的情况。
It is true that on all previous versions of Visual
Studio, you must use _snprintf() function. But VS 2014 onwards you should not #define it with _snprintf().
在早期的Visual Studio中你必须定义函数_snprintf(),但在2014及其后续版本中,你无需这么做。
Somewhere in your code or most likely in headers, this is done and
hence the error.
Check that and remove that #define.
part of C99 specifications.
To enable C99 support
add this in your program
In case you don't know what _MSC_VER macro values are
2、选择要编译的版本为win32还是X64,然后编辑库文件。编译完成后会出现“fatal error C1189: #error: Macro definition of snprintf conflicts with Standard Library function declaration”的错误。
这时候需要修改源码中的tif_config.h文件。该文件在源码目录中只有一个,因此找到之后直接修改即可。将源码中的
#ifdef _WIN32
#define
snprintf _snprintf // 将此行注释掉
#define
lfind _lfind
#endif
// _WIN32
修改为:
#ifdef _WIN32//#define snprintf _snprintf#define
lfind _lfind#endif // _WIN32
这是因为在早期的VC自带的C标准库中确实没有snprintf这个函数,只有_snprintf。但是VS2015下是有的,所以这里不注释掉会有重定义的问题。
也可以修改为:
#ifdef
_WIN32
#if
defined(_MSC_VER) && _MSC_VER < 1900
#define
snprintf _snprintf
#endif
#define
lfind _lfind
#endif
// _WIN32
3、再次进行编译,编译完成后可以到源码目录下的Dist目录拷贝FreeImage.h和库文件。
错误原因分析:
目前,在很多的库和程序中使用函数通过定义函数_snprintf()的方式来使用snprintf(),因为系统中已经定义好了_snprintf()函数。
#define snprintf _snprintf
最终,Visual Studio 14 中开始定义了snprintf()!
既然在编译器中开始支持snprintf()函数,因此,我们无需进行重定义(画蛇添足)。定义这个函数就会造成overshadow已经在stdio.h中定义的snprintf()。为了约束用户的这种方式,系统在 stdio.h文件中添加了如下的提示:
#ifdef snprintf
#error: Macro definition of snprintf conflicts
with Standard Library function declaration”
#endif
因此,就会造成上面不编译不成功的情况。
It is true that on all previous versions of Visual
Studio, you must use _snprintf() function. But VS 2014 onwards you should not #define it with _snprintf().
在早期的Visual Studio中你必须定义函数_snprintf(),但在2014及其后续版本中,你无需这么做。
Somewhere in your code or most likely in headers, this is done and
hence the error.
Check that and remove that #define.
snprintf()is
part of C99 specifications.
To enable C99 support
add this in your program
#if _MSC_VER>=1900 # define STDC99 #endif
In case you don't know what _MSC_VER macro values are
... MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015) MSVC++ 12.0 _MSC_VER == 1800 (Visual Studio 2013) MSVC++ 11.0 _MSC_VER == 1700 (Visual Studio 2012) MSVC++ 10.0 _MSC_VER == 1600 (Visual Studio 2010) MSVC++ 9.0 _MSC_VER == 1500 (Visual Studio 2008) MSVC++ 8.0 _MSC_VER == 1400 (Visual Studio 2005) MSVC++ 7.1 _MSC_VER == 1310 (Visual Studio .NET 2003) MSVC++ 7.0 _MSC_VER == 1300 MSVC++ 6.0 _MSC_VER == 1200 MSVC++ 5.0 _MSC_VER == 1100 MSVC++ 4.0 _MSC_VER == 1000 MSVC++ 2.0 _MSC_VER == 900 MSVC++ 1.0 _MSC_VER == 800 C/C++ 7.0 _MSC_VER == 700 C 6.0 _MSC_VER == 600
相关文章推荐
- 雷塞SMC304系列控制器VC6.0例程在VS2015下编译遇到的若干问题及解决办法
- DirectX在VS2015上编译时遇到“无法解析的外部符号 __vsnwprintf”的解决方法及原因
- 编译opencv3.2时遇到的问题(VS2015)
- FreeImage编译及遇到问题解决
- VS2015使用Git遇到的问题及解决办法
- OGRE 2.1 使用VS2015编译的过程以及问题的解决
- vs2013 Qt5.7编译osgearth2.7遇到的问题及解决办法
- VS2015解决非Unicode编码包含中文字段无法编译的问题
- 从VS2008+QT4到VS2015+QT5迁移过程中遇到的问题及解决方法
- vs 2015 结合新配置的IIS 发布网站过程中遇到的问题及解决办法?
- VS2015启动遇到的一些问题和解决方法
- windows7下 VS2015 编译VLFeat所遇到的问题
- 初学者使用vs2013编译c语言程序遇到问题及解决办法。
- QtCreator 4.0 Q5.7 VS2015 源码中有中文导致编译失败的问题的解决方法
- vs2015编译 jrtp库使用过程中遇到的一些问题
- 用vs2013编译用vs2015写的memcached遇到的平台问题
- [置顶] vs2015编译运行程序遇到应用程序无法正常启动0xc000007b的问题
- 使用VS2015编译Synergyd历程,解决Synergd.exe占用CPU高的问题
- 初学者使用vs2013编译c语言程序遇到问题及解决办法。