Visual Studio + Boost error

Visual Studio + Boost error

本文关键字:error Boost Studio Visual      更新时间:2023-10-16

我正试图在Visual Studio C++Express 2010中使用Boost构建一个解决方案,但出现以下错误:

1>------ Build started: Project: MEDsLDAc, Configuration: Release Win32 ------
1>  MedLDA.cpp
1>D:_downloadboost_1_53_0boost/math/constants/calculate_constants.hpp(152): error C2988: unrecognizable template declaration/definition
1>D:_downloadboost_1_53_0boost/math/constants/calculate_constants.hpp(152): error C2059: syntax error : 'constant'
1>D:_downloadboost_1_53_0boost/math/constants/calculate_constants.hpp(153): error C2143: syntax error : missing ')' before '>'
1>D:_downloadboost_1_53_0boost/math/constants/calculate_constants.hpp(184): error C2244: 'boost::math::constants::detail::constant_euler<T>::compute' : unable to match function definition to an existing declaration
1>          definition
1>          'T boost::math::constants::detail::constant_euler<T>::compute(void)'
1>          existing declarations
1>          'T boost::math::constants::detail::constant_euler<T>::compute(void)'
1>MedLDA.cpp(385): warning C4244: 'initializing' : conversion from 'double' to 'long', possible loss of data
1>MedLDA.cpp(426): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          C:Program FilesMicrosoft Visual Studio 10.0VCincludestring.h(105) : see declaration of 'strcpy'
1>MedLDA.cpp(485): warning C4244: 'initializing' : conversion from 'double' to 'long', possible loss of data
1>MedLDA.cpp(608): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          C:Program FilesMicrosoft Visual Studio 10.0VCincludestring.h(105) : see declaration of 'strcpy'
1>MedLDA.cpp(609): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          C:Program FilesMicrosoft Visual Studio 10.0VCincludestring.h(105) : see declaration of 'strcpy'
1>MedLDA.cpp(636): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>          C:Program FilesMicrosoft Visual Studio 10.0VCincludestring.h(105) : see declaration of 'strcpy'
1>MedLDA.cpp(730): warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
1>MedLDA.cpp(963): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
1>MedLDA.cpp(1150): warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data
1>MedLDA.cpp(1241): warning C4244: 'initializing' : conversion from 'double' to 'long', possible loss of data
1>MedLDA.cpp(1296): warning C4244: 'initializing' : conversion from 'double' to 'long', possible loss of data
========== Build: 0 succeeded, 1 failed, 2 up-to-date, 0 skipped ==========

如何修复?

更新:该软件为MedLDAc,可在此处获得:http://www.ml-thu.net/~jun/medda.shtml

作者说建筑适合他。

由于您还没有显示任何代码,我们只能猜测。我的猜测是,你#define的某个宏扰乱了Boost.Math的代码。也许像#define M ......

更新:事实证明我的猜测是正确的。看看MedLDAc/MEDsLDAc/cokus.h file:

#define M              (397)                 // a period parameter

立即的解决方法是将MedLDA.cpp中的#include <boost/math/special_functions/gamma.hpp>行移动到StdAfx.h之后的第一个include,这样上述宏就不会影响gamma.hpp中声明的模板。

附言:定义一个字母的宏是一个非常非常糟糕的主意。