您的位置:首页 > 其它

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.

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息