Question

I'm trying to build xercesc 3.1 on 64bit Windows 7 using Visual Studio 2005. I downloaded the source from the official site and followed the instructions given there (basically, just 'open the .sln and build project XercesLib), but I get the following compilation errors:

error C2733: second C linkage of overloaded function '_interlockedbittestandset' not allowed
error C2733: second C linkage of overloaded function '_interlockedbittestandreset' not allowed

I noticed that the SDK version in this error message was 6.1 whereas 7.0 was released with Windows 7. So I tried adding C:\Program Files\Microsoft SDKs\Windows\v7.0\include to the Additional Include Directories of the project, but this had no effect.

I also checked that I had opened the right sln file - I went with the one labelled 'VC8', which I believe should correspond to VS2005.

Was it helpful?

Solution

After some more searching with different terms, I discovered that this is a known bug in VS2005 when including both winnt.h and intrin.h.

The easiest workaround for this is to use the preprocessor to rename the offending functions when including one of the headers.

However, in the case of Xercesc, the functions are used, so a little more work is required. I used the solution detailed in 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

Which allowed compilation to complete error-free.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top