We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1097 - SDL_atomic.h creates compile errors in Visual Studio 2005
Summary: SDL_atomic.h creates compile errors in Visual Studio 2005
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: atomic (show other bugs)
Version: 2.0.3
Hardware: x86 Windows (All)
: P1 blocker
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-21 01:52 UTC by John Wilson
Modified: 2015-05-26 13:29 UTC (History)
2 users (show)

See Also:


Attachments
Fix for Visual Studio 2005 (1.47 KB, patch)
2011-01-22 12:03 UTC, Sam Lantinga
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description John Wilson 2011-01-21 01:52:11 UTC
1>c:\program files\microsoft visual studio 8\vc\include\ivec.h(233) : error C2733: second C linkage of overloaded function 'cmpeq' not allowed
1>        c:\program files\microsoft visual studio 8\vc\include\ivec.h(233) : see declaration of 'cmpeq'

This is only the first of many errors regarding C linkage and overloaded functions. I traced it all back to SDL_atomic.h, where 'extern "C" {' is used, and while it is still in effect, 'intrin.h' is included, which leads to a long string of includes that end up at 'ivec.h'. This file uses function overloading and is not suitable for C linkage, thus I get lots of compiler errors in projects that use SDL.
Comment 1 Sam Lantinga 2011-01-21 09:38:57 UTC
I assume you're working on a C++ project?

Does it work to close the C linkage around the include?

e.g.
}
#include <intrin.h>
extern "C" {
Comment 2 John Wilson 2011-01-21 19:29:13 UTC
(In reply to comment #1)
> I assume you're working on a C++ project?
> 
> Does it work to close the C linkage around the include?
> 
> e.g.
> }
> #include <intrin.h>
> extern "C" {

Yes, I'm using C++. I tried what you suggested, and it made it through the whole of SDL.h without errors. However, my project includes SDL_opengl.h right after that, which leads to winnt.h and these 2 errors:

1>c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(3112) : error C2733: second C linkage of overloaded function '_interlockedbittestandset' not allowed
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(3109) : see declaration of '_interlockedbittestandset'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(3118) : error C2733: second C linkage of overloaded function '_interlockedbittestandreset' not allowed
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winnt.h(3115) : see declaration of '_interlockedbittestandreset'

I would say that intrin.h and winnt.h are conflicting somehow, as I don't get those errors if I comment out the SDL_atomic header.

I found that if I defined _PREFIX_ it skips over that section of winnt.h and my project compiles successfully.
Comment 3 Sam Lantinga 2011-01-21 23:23:32 UTC
*sigh*

What happens if you just put these in a file by themselves?
#include <intrin.h>
#include <windows.h>
#include <winnt.h>
Comment 4 Sam Lantinga 2011-01-21 23:27:28 UTC
A little googling shows that this is a common problem.  Hmm.
Comment 5 Sam Lantinga 2011-01-21 23:28:55 UTC
Are you using Visual Studio 2005?
Comment 6 Sam Lantinga 2011-01-21 23:32:41 UTC
Nevermind, it's in the subject. :)
Comment 7 Sam Lantinga 2011-01-22 12:03:03 UTC
Created attachment 556 [details]
Fix for Visual Studio 2005
Comment 8 Ryan C. Gordon 2011-08-21 00:37:23 UTC
Fixing up some bug report metadata.

--ryan.
Comment 9 Ryan C. Gordon 2011-08-21 00:55:25 UTC
Resolving bug: Sam committed the patch in Attachment #556 [details] as hg changeset 1e94e68525d5.

--ryan.
Comment 10 vol_ya 2014-08-12 15:02:55 UTC
I have the same issue with VS 2008 and SDL 2.0.3.
Could you please look int this?
Comment 11 vol_ya 2014-08-12 15:04:40 UTC
I'm trying to move from SDL 1.2.15 to SDL 2.0.3
Comment 12 vol_ya 2014-08-12 15:24:54 UTC
Not sure if this error is related to "atomic" component, but anyway here is a part of the errors:


Error	12	error C2733: second C linkage of overloaded function 'cmpeq' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	233
Error	14	error C2733: second C linkage of overloaded function 'cmpneq' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	234
Error	20	error C2733: second C linkage of overloaded function 'unpack_low' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	240
Error	22	error C2733: second C linkage of overloaded function 'unpack_high' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	241
Error	24	error C2733: second C linkage of overloaded function 'cmpeq' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	308
Error	26	error C2733: second C linkage of overloaded function 'cmpneq' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	309
Error	28	error C2733: second C linkage of overloaded function 'unpack_low' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	311
Error	30	error C2733: second C linkage of overloaded function 'unpack_high' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	312
Error	33	error C2733: second C linkage of overloaded function 'cmpeq' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	346
Error	35	error C2733: second C linkage of overloaded function 'cmpneq' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	347
Error	37	error C2733: second C linkage of overloaded function 'unpack_low' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	349
Error	39	error C2733: second C linkage of overloaded function 'unpack_high' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	350
Error	41	error C2733: second C linkage of overloaded function 'operator *' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	422
Error	43	error C2733: second C linkage of overloaded function 'cmpeq' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	425
Error	45	error C2733: second C linkage of overloaded function 'cmpneq' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	426
Error	47	error C2733: second C linkage of overloaded function 'cmpgt' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	427
Error	49	error C2733: second C linkage of overloaded function 'cmplt' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	428
Error	51	error C2733: second C linkage of overloaded function 'cmple' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	429
Error	53	error C2733: second C linkage of overloaded function 'cmpge' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	430
Error	55	error C2733: second C linkage of overloaded function 'unpack_low' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	432
Error	57	error C2733: second C linkage of overloaded function 'unpack_high' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	433
Error	63	error C2733: second C linkage of overloaded function 'operator *' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	509
Error	65	error C2733: second C linkage of overloaded function 'cmpeq' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	510
Error	67	error C2733: second C linkage of overloaded function 'cmpneq' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	511
Error	69	error C2733: second C linkage of overloaded function 'sat_add' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	513
Error	71	error C2733: second C linkage of overloaded function 'sat_sub' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	514
Error	73	error C2733: second C linkage of overloaded function 'unpack_low' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	516
Error	75	error C2733: second C linkage of overloaded function 'unpack_high' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	517
Error	77	error C2733: second C linkage of overloaded function 'cmpeq' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	544
Error	79	error C2733: second C linkage of overloaded function 'cmpneq' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	545
Error	81	error C2733: second C linkage of overloaded function 'unpack_low' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	547
Error	83	error C2733: second C linkage of overloaded function 'unpack_high' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	548
Error	85	error C2733: second C linkage of overloaded function 'cmpeq' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	617
Error	87	error C2733: second C linkage of overloaded function 'cmpneq' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	618
Error	89	error C2733: second C linkage of overloaded function 'cmpgt' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	619
Error	91	error C2733: second C linkage of overloaded function 'cmplt' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	620
Error	93	error C2733: second C linkage of overloaded function 'cmple' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	621
Error	95	error C2733: second C linkage of overloaded function 'cmpge' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	622
Error	97	error C2733: second C linkage of overloaded function 'unpack_low' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	624
Error	99	error C2733: second C linkage of overloaded function 'unpack_high' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	625
Error	101	error C2733: second C linkage of overloaded function 'sat_add' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	627
Error	103	error C2733: second C linkage of overloaded function 'sat_sub' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	628
Error	105	error C2733: second C linkage of overloaded function 'cmpeq' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	694
Error	107	error C2733: second C linkage of overloaded function 'cmpneq' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	695
Error	109	error C2733: second C linkage of overloaded function 'unpack_low' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	697
Error	111	error C2733: second C linkage of overloaded function 'unpack_high' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	698
Error	113	error C2733: second C linkage of overloaded function 'sat_add' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	700
Error	115	error C2733: second C linkage of overloaded function 'sat_sub' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	701
Error	118	error C2733: second C linkage of overloaded function 'pack_sat' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	704
Error	121	error C2733: second C linkage of overloaded function 'operator &' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	718
Error	123	error C2733: second C linkage of overloaded function 'operator |' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	718
Error	125	error C2733: second C linkage of overloaded function 'operator ^' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	718
Error	127	error C2733: second C linkage of overloaded function 'andnot' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	718
Error	129	error C2733: second C linkage of overloaded function 'operator &' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	719
Error	131	error C2733: second C linkage of overloaded function 'operator |' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	719
Error	133	error C2733: second C linkage of overloaded function 'operator ^' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	719
Error	135	error C2733: second C linkage of overloaded function 'andnot' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	719
Error	137	error C2733: second C linkage of overloaded function 'operator &' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	720
Error	139	error C2733: second C linkage of overloaded function 'operator |' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	720
Error	141	error C2733: second C linkage of overloaded function 'operator ^' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	720
Error	143	error C2733: second C linkage of overloaded function 'andnot' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	720
Error	145	error C2733: second C linkage of overloaded function 'operator &' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	721
Error	147	error C2733: second C linkage of overloaded function 'operator |' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	721
Error	149	error C2733: second C linkage of overloaded function 'operator ^' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	721
Error	151	error C2733: second C linkage of overloaded function 'andnot' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	721
Error	153	error C2733: second C linkage of overloaded function 'operator &' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	722
Error	155	error C2733: second C linkage of overloaded function 'operator |' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	722
Error	157	error C2733: second C linkage of overloaded function 'operator ^' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	722
Error	159	error C2733: second C linkage of overloaded function 'andnot' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	722
Error	161	error C2733: second C linkage of overloaded function 'operator &' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	723
Error	163	error C2733: second C linkage of overloaded function 'operator |' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	723
Error	165	error C2733: second C linkage of overloaded function 'operator ^' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	723
Error	167	error C2733: second C linkage of overloaded function 'andnot' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	723
Error	169	error C2733: second C linkage of overloaded function 'operator &' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	724
Error	171	error C2733: second C linkage of overloaded function 'operator |' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	724
Error	173	error C2733: second C linkage of overloaded function 'operator ^' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	724
Error	175	error C2733: second C linkage of overloaded function 'andnot' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	724
Error	177	error C2733: second C linkage of overloaded function 'operator &' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	725
Error	179	error C2733: second C linkage of overloaded function 'operator |' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	725
Error	181	error C2733: second C linkage of overloaded function 'operator ^' not allowed	c:\program files (x86)\microsoft visual studio 9.0\vc\include\ivec.h	725
Comment 13 Sam Lantinga 2014-08-17 20:48:12 UTC
Can you try with the latest snapshot?
http://www.libsdl.org/tmp/SDL-2.0.zip

I'm building here with Visual Studio 2008 with no problems.  I created a file called test.cpp with these lines in it, and it compiled just fine:

#include <windows.h>
#include "SDL_atomic.h"

If you're still having problems, can you post a code snippet that when compiled alone, shows the problem?

Thanks!
Comment 14 Sam Lantinga 2015-05-26 13:29:37 UTC
No response, I'm going to assume this is fixed.