I am making a C++ game and integrating Steam's API on Windows MinGW GCC via MSYS2 environment. I am successfully linking to the library, and some of the functions run properly.
I am able to initialize steamworks and run SteamFriends()->GetPersonaName(), and it returns my own steam user as expected.
However, when I run SteamUser()->GetSteamID() it gives me a segfault. Upon debugging, I have found that SteamUser() returns an address (it is not NULL), but the address does not address a valid ISteamUser class/struct. I am beginning to believe that perhaps the DLL that windows loads for steam_api is not the one which I linked for.
Is there any way to determine this? Also does anyone have any other debug methodologies they would use to try to identify the problem?
I have also compiled an identical application using visual studio and it does not experience the segfault, so I have isolated the issue to something external to my code for certain, probably relating to the way the DLL is linked.
SteamUser()->GetSteamID()
crash is due to the C++ ABI differences between MINGW (used by your app) and MSVC (used by Steam DLLs). Basically GetSteamID()
returns not just integer value, but CSteamID
class, and the binary conventions for passing a class value are different in different compilers.
Related SteamWorks discussions (accessible only for approved Steam developers):
To fix this call (and possibly other SteamAPI calls with the same problem), you can use C API from <steam/steam_api_flat.h>
, which does not suffer from ABI differences:
SteamAPI_ISteamUser_GetSteamID(SteamUser())
It is OK to mix usage of C and C++ API, so you can still use C++ API most of the time, and use C API only for problematic calls.
Or you can switch to MSVC or MSVC-clang.