Пример #1
0
//----------------------------------------------------------------------------//
DynamicModule::DynamicModule(const String& name) :
    d_pimpl(CEGUI_NEW_AO Impl(name))
{
	if (name.empty())
		return;

    if (!hasDynamicLibraryExtension(d_pimpl->d_moduleName))
        addLibraryNameSuffixes(d_pimpl->d_moduleName);

    d_pimpl->d_handle = DynLibLoad(d_pimpl->d_moduleName);

#if defined(__linux__) || defined(__APPLE__) || defined(__MINGW32__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__HAIKU__)
    // see if adding a leading 'lib' helps us to open the library
    if (!d_pimpl->d_handle && d_pimpl->d_moduleName.compare(0, 3, "lib") != 0)
    {
        d_pimpl->d_moduleName.insert(0, "lib");
        d_pimpl->d_handle = DynLibLoad(d_pimpl->d_moduleName);
    }
#endif

#if defined(__CYGWIN__)
    // see if adding a leading 'cyg' helps us to open the library
    if (!d_pimpl->d_handle && d_pimpl->d_moduleName.compare(0, 3, "cyg") != 0)
    {
        d_pimpl->d_moduleName.insert(0, "cyg");
        d_pimpl->d_handle = DynLibLoad(d_pimpl->d_moduleName);
    }
#endif

    // check for library load failure
    if (!d_pimpl->d_handle)
        CEGUI_THROW(GenericException("Failed to load module '" +
            d_pimpl->d_moduleName + "': " + getFailureString()));
}
Пример #2
0
DynamicModule::DynamicModule(const String& name) :
    d_moduleName(name)
{
	//If nothing is passed, don't load anything...
	if(name.empty())
	{
		d_handle = 0;
		return;
	} // if(name.empty())

#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)  || defined(__HAIKU__)
    #if defined(CEGUI_HAS_VERSION_SUFFIX) || defined(CEGUI_HAS_BUILD_SUFFIX)
        // check if we are being asked to open a CEGUI .so, if so postfix the
        // name with our package version
        if (d_moduleName.substr(0, 5) == "CEGUI" ||
            d_moduleName.substr(0, 8) == "libCEGUI")
        {
            // strip .so extension before postfixing, will get added again below
            if (d_moduleName.substr(d_moduleName.length() - 3, 3) == ".so")
                d_moduleName = d_moduleName.substr(0, d_moduleName.length() - 3);

            #ifdef CEGUI_HAS_BUILD_SUFFIX
                // append a suffix (like _d for debug builds, etc)
                d_moduleName += CEGUI_BUILD_SUFFIX;
            #endif

            #ifdef CEGUI_HAS_VERSION_SUFFIX
                d_moduleName += "-";
                d_moduleName += CEGUI_VERSION_SUFFIX;
            #endif
        }
    #endif
    // dlopen() does not add .so to the filename, like windows does for .dll
    if (d_moduleName.substr(d_moduleName.length() - 3, 3) != ".so")
        d_moduleName += ".so";
#endif
    // Optionally add a _d to the module name for the debug config on Win32
#if defined(__WIN32__) || defined(_WIN32)
    // if name has .dll extension, assume it's complete and do not touch it.
    if (d_moduleName.substr(d_moduleName.length() - 4, 4) != ".dll")
    {
        #ifdef CEGUI_HAS_BUILD_SUFFIX
            // append a suffix (like _d for debug builds, etc)
            d_moduleName += CEGUI_BUILD_SUFFIX;
        #endif

        #ifdef CEGUI_HAS_VERSION_SUFFIX
            d_moduleName += "-";
            d_moduleName += CEGUI_VERSION_SUFFIX;
        #endif
    }
#endif

    d_handle = DYNLIB_LOAD(d_moduleName.c_str());

#if defined(__linux__) || defined(__MINGW32__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__HAIKU__)
    if (!d_handle)
    {
        // see if we need to add the leading 'lib'
        if (d_moduleName.substr(0, 3) != "lib")
        {
            d_moduleName.insert(0, "lib");
            d_handle = DYNLIB_LOAD(d_moduleName.c_str());
        }
    }
#endif

    // check for library load failure
    if (!d_handle)
        CEGUI_THROW(GenericException(
            "DynamicModule::DynamicModule - Failed to load module '" +
            d_moduleName + "': " + getFailureString()));
}