Steamworks redefines ARRAY_COUNT macro - compile error

My brother wrote a networking plugin (for 4.11 or something like that).

When I tried adding it to my 4.23 project I had to change many Engine related function calls but after hours of searching compilation still fails. The compile errors (100+) shown are only syntax errors in multiple .gen.cpp files. (By the way, I’d welcome advice on how to make UE4 C++ development less annoying)

Now the only and last clue is this warning here:

e:\program files\epic games\ue_4.23\engine\source\thirdparty\steamworks\steamv142\sdk\public\steam\steamtypes.h(99): warning C4005: 'ARRAY_COUNT': macro redefinition

All (I didn’t really check all) the syntax errors are either brackets or commas in lines where ARRAY_COUNT is indeed used.

I found this forum post where mordentral said:

The first error is another thing entirely though, steam appears to have a macro that is conflicting with an Unreal Engine macro. I looked it up and this was a problem before on visual studio but they merged a fix for it into the engine. I am directly accessing the file that caused the issue so it appears again when not using visual studio.

I included Epics #undef of the macro in my header as well, should fix it for you now. Hopefully I can remove that at some point though when / if either UE4 or Steamworks redefines that macro.

Also this forum post says to include and #undef in the files that reference the Engine like so:

#ifdef ARRAY_COUNT
#undef ARRAY_COUNT
#endif

I tried adding it to the file that references the steam API and the warning was gone but the errors where still there. Also OP didn’t have problems on Windows.

So how can I fix it? Is this even related to the ARRAY_COUNT macro?

I guess by now I might have even finished implementing this in BP…

Thanks in advance and cheers!

EDIT: Tried with steamworks version 139 and also updated to 146 with no changes.

Hey LordStuff, I have encountered this problem, although not in windows. However the fix should be the same. First of all it’s important to note that the definitions happen before everything else so you shouldn’t need to add this everywhere, just on one of the steam definitions. Check for some place where the include of steam libraries happens and do the undefine BEFORE the include of the steam utilities and after all the other includes.

for example, if you have on one of the files this:

#include "ThirdParty/Steamworks/Steamv142/sdk/public/steam/steam_api.h"

try putting the undef before this include:

#ifdef ARRAY_COUNT
#undef ARRAY_COUNT
#endif
#include "ThirdParty/Steamworks/Steamv142/sdk/public/steam/steam_api.h"

Blog post on the issue

There’s only one file referencing

#include "steam/steam_api.h"

But pasting the undef in front didn’t solve it.
This is driving me nuts…

Do you have any other idea on what might be the issue? :’(

after that error i think there was a mention of the parts where the code was conflicting. Can you provide what it said ?

also just to make sure that thats the conflicting file. are you able to compile without it?

Here is a snippet of a previous build. The only reference to the steam API is in a “MainMenuTypes.h” and most other files of the plugin rely on that, so removing it would break it. But the project compiles without the plugin.

link text

I can confirm that this error occurs on my ubuntu-distribution as well, provided the steam_api include is in a header with uclasses or ustructs. My guess is that the problem is caused in the build-tool generated source files.

An “easy” fix, depending on your code, is to move the api-include to a source file. In this case the undefine works like a charm.