Dirk Reiners wrote:
(Just had an idea about this).

Actually, one could make a mechanism for this. Since the VC compiler defines _DEBUG, _DLL and _MT depending on which runtime-libs you compile against, it would be quite easy to write something in the header file (say osgInit.h) that pass this information (i.e. the client application's settings) to the compiled dll's in OpenSG, which can then issue a warning.

I'll see if I can cook something up that solves this.

sounds interesting, let me know what you come up with. This is just a
very common problem, an automated warning would be useful.
I have managed to cobble together something which gives you a chance to detect this at runtime, see the attached file.

It certainly traps mismatches, and currently forces the user to link to MultiThreaded-DLL (just modify the #ifndefs at top of detect.h to change this).

It is not the most generic thing, but works for me and should work for OpenSG as well.

Best Regards,
/Marcus




/// Detect.h 
////////////////////////////////////////////////////////////////////////

#ifndef _DLL
#error Must link with DLL version of runtime libs
#endif
#ifndef _MT
#error Must link with multi-threaded version of runtime libs
#endif

// rtl-configuration data
    struct RuntimeConfig
    {

        RuntimeConfig();

        bool operator ==(const RuntimeConfig& r);

        bool m_mt;
        bool m_dll;
        bool m_debug;
    };

    static bool checkRuntimeConfig(const RuntimeConfig& cfg);


// must be in header to capture info at compile time.
inline Main::RuntimeConfig::RuntimeConfig()
{
    #ifdef _DEBUG
    m_debug = true;
    #else
    m_debug = false;
    #endif
    #ifdef _DLL
    m_dll = true;
    #else
    m_dll = false;
    #endif
    #ifdef _MT
    m_mt = true;
    #else
    m_mt = false;
    #endif
}

std::ostream & operator <<
    (std::ostream & os, const RuntimeConfig & cfg);

/// Detect.cpp 
////////////////////////////////////////////////////////////////////////

#include ... 

MyLogClass s_log;

bool checkRuntimeConfig(const RuntimeConfig& client)
{
    RuntimeConfig lib;
    bool ok = lib == client;
    if (!ok) {
        std::ostringstream os;
        os << "MSVC runtime config mismatch.\n";
        os << "Lib compiled with " << lib << "\n";
        os << "Client compiled with " << client << "\n";
        s_log.fatal(os.str()); 
        abort();
    }

    return ok;
}

bool Main::RuntimeConfig::operator==(const Main::RuntimeConfig& r)
{
    return m_mt == r.m_mt && m_dll == r.m_dll && m_debug == r.m_debug;
}

std::ostream &operator<<(std::ostream& os, const RuntimeConfig& cfg)
{
    os << (cfg.m_debug ? "debug" : "release") << ' ';
    os << (cfg.m_dll ? "dynamic" : "static") << ' ';
    os << (cfg.m_mt ? "multi" : "single") << "-threaded";
    return os;
}

Reply via email to