我正在尝试使用Visual Studio 2005在64位Windows 7上构建xercesc 3.1。我从官方网站下载了源代码并跟随instructions given there(基本上,只需打开.sln并构建项目XercesLib) ,但我得到以下编译错误:
error C2733: second C linkage of overloaded function '_interlockedbittestandset' not allowed
error C2733: second C linkage of overloaded function '_interlockedbittestandreset' not allowed
我注意到此错误消息中的SDK版本为 6.1 ,而Windows 7发布了 7.0 。所以我尝试将C:\Program Files\Microsoft SDKs\Windows\v7.0\include
添加到其他包含该项目的目录,但这没有效果。
我还检查过我打开了正确的sln文件 - 我选择了标有'VC8'的文件,我相信它应该与VS2005相对应。
答案 0 :(得分:1)
在使用不同的术语进行更多搜索后,我发现当包含winnt.h和intrin.h时,这是一个known bug in VS2005。
最简单的解决方法是在包含其中一个标头时使用预处理器rename the offending functions。
但是,在Xercesc的情况下,使用了函数,因此需要做更多的工作。我使用了this blog post中详述的解决方案:
#if _MSC_VER >= 1400
// Following 8 lines: workaround for a bug in some older SDKs
# pragma push_macro("_interlockedbittestandset")
# pragma push_macro("_interlockedbittestandreset")
# pragma push_macro("_interlockedbittestandset64")
# pragma push_macro("_interlockedbittestandreset64")
# define _interlockedbittestandset _local_interlockedbittestandset
# define _interlockedbittestandreset _local_interlockedbittestandreset
# define _interlockedbittestandset64 _local_interlockedbittestandset64
# define _interlockedbittestandreset64 _local_interlockedbittestandreset64
# include <intrin.h> // to force the header not to be included elsewhere
# pragma pop_macro("_interlockedbittestandreset64")
# pragma pop_macro("_interlockedbittestandset64")
# pragma pop_macro("_interlockedbittestandreset")
# pragma pop_macro("_interlockedbittestandset")
#endif
允许编译完成无错误。