Trouble Compiling Session Manager from C++ Guide Example

I’m just getting my C++ Dev environment set up. I copied the code from the C++ Client Guide. Then I tried to create an instance of NakamaSessionManager in my Main function. And I’m getting a bunch of build errors. Can anybody help? I thought I followed the instructions.

"mismatch detected for ‘_ITERATOR_DEBUG_LEVEL’: value ‘0’ doesn’t match value ‘2’

#include <iostream>
#include "nakama-cpp/Nakama.h"


using namespace Nakama;
using namespace std;



class NakamaSessionManager
{
public:
    NakamaSessionManager()
    {
        NClientParameters parameters;

        _client = createDefaultClient(parameters);
    }

    void start(const string& deviceId)
    {
        // to do: read session token from your storage
        string sessionToken;

        if (!sessionToken.empty())
        {
            // Lets check if we can restore a cached session.
            auto session = restoreSession(sessionToken);

            if (!session->isExpired())
            {
                // Session was valid and is restored now.
                _session = session;
                return;
            }
        }

        auto successCallback = [this](NSessionPtr session)
        {
            _session = session;

            // to do: save session token in your storage
            std::cout << "session token: " << session->getAuthToken() << std::endl;
        };

        auto errorCallback = [](const NError& error)
        {
        };

        _client->authenticateDevice(deviceId, opt::nullopt, opt::nullopt, {}, successCallback, errorCallback);
    }

protected:
    NClientPtr _client;
    NSessionPtr _session;
};




int main()
{

    NakamaSessionManager MyClient;  //calling the class exactly as in the example and failing in construction

    std::cout << "Hello World!\n";
}

Hey @Mehoo462 :wave:

I think this happens when you link against a release library with a debug project in some Visual Studio projects.

Could you add _ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH to your C++ preprocessor definitions in your editor?

Hi! Thanks for the prompt reply. That’s encouraging. :slight_smile:
I think followed your suggestion. But I’m still getting the same errors. I made the change and restarted VS2019 just to make sure.

Okay… the problem occurs in Step 3 of the “Setup for Visual Studio projects” of the C++ guide.

It says:

  1. Add all .lib files located in libs folder in Linker > Input > Additional Dependencies

You don’t want to add all ‘.lib’ files to the Additional dependencies. You want to add all the .lib files in the debug folder to Additional Dependencies for your Debug Configuration. And all the files in the Release folder to Additional dependencies for your Release configuration.

If you load both the release and debug libraries at once, you wind up with contradictory Debug Levels, and VS2019 is unhappy about that.

1 Like

@Mehoo462 brilliant find. I am going to update the readme with these new instructions.

Thanks. I’m concerned there still might be an issue with the Readme though. I think I followed the directions properly, but I’m still not able to build successfully.

Once I corrected the issue with the Additional Dependencies I ran into a problem with Unresolved External Symbol Errors. Do you have any thoughts that problem?

https://forum.heroiclabs.com/t/unresolved-external-symbol-errors/1447