cpl/cplgetsymbol.cpp
void *CPLGetSymbol( const char * pszLibrary, const char * pszSymbolName )

{
    void        *pLibrary;
    void        *pSymbol;

    pLibrary = dlopen(pszLibrary, RTLD_LAZY);
    if( pLibrary == NULL )
    {
        CPLError( CE_Failure, CPLE_AppDefined,
                  "%s", dlerror() );
        return NULL;
    }

    pSymbol = dlsym( pLibrary, pszSymbolName );

#if (defined(__APPLE__) && defined(__MACH__))
    /* On mach-o systems, C symbols have a leading underscore and depending
     * on how dlcompat is configured it may or may not add the leading
     * underscore.  So if dlsym() fails add an underscore and try again.
     */
    if( pSymbol == NULL )
    {
        char withUnder[strlen(pszSymbolName) + 2];
        withUnder[0] = '_'; withUnder[1] = 0;
        strcat(withUnder, pszSymbolName);
        pSymbol = dlsym( pLibrary, withUnder );
    }
#endif

    if( pSymbol == NULL )
    {
        CPLError( CE_Failure, CPLE_AppDefined,
                  "%s", dlerror() );
        return NULL;
    }
    
    return( pSymbol );
}
/**
 * Fetch a function pointer from a shared library / DLL.
 *
 * This function is meant to abstract access to shared libraries and
 * DLLs and performs functions similar to dlopen()/dlsym() on Unix and
 * LoadLibrary() / GetProcAddress() on Windows.
 *
 * If no support for loading entry points from a shared library is available
 * this function will always return NULL.   Rules on when this function
 * issues a CPLError() or not are not currently well defined, and will have
 * to be resolved in the future.
 *
 * Currently CPLGetSymbol() doesn't try to:
 * <ul>
 *  <li> prevent the reference count on the library from going up
 *    for every request, or given any opportunity to unload      
 *    the library.                                            
 *  <li> Attempt to look for the library in non-standard         
 *    locations.                                              
 *  <li> Attempt to try variations on the symbol name, like      
 *    pre-prending or post-pending an underscore.
 * </ul>
 * 
 * Some of these issues may be worked on in the future.
 *
 * @param pszLibrary the name of the shared library or DLL containing
 * the function.  May contain path to file.  If not system supplies search
 * paths will be used.
 * @param pszSymbolName the name of the function to fetch a pointer to.
 * @return A pointer to the function if found, or NULL if the function isn't
 * found, or the shared library can't be loaded.
 */
Fetch a function pointer from a shared library / DLL.
This function is meant to abstract access to shared libraries and
DLLs and performs functions similar to dlopen()/dlsym() on Unix and
LoadLibrary() / GetProcAddress() on Windows.

If no support for loading entry points from a shared library is available
this function will always return NULL.   Rules on when this function
issues a CPLError() or not are not currently well defined, and will have
to be resolved in the future.

Currently CPLGetSymbol() doesn't try to:

 prevent the reference count on the library from going up
for every request, or given any opportunity to unload
the library.
 Attempt to look for the library in non-standard
locations.
 Attempt to try variations on the symbol name, like
pre-prending or post-pending an underscore.

Some of these issues may be worked on in the future.

@param pszLibrary the name of the shared library or DLL containing
the function.  May contain path to file.  If not system supplies search
paths will be used.
@param pszSymbolName the name of the function to fetch a pointer to.
@return A pointer to the function if found, or NULL if the function isn't
found, or the shared library can't be loaded.
Fetch a function pointer from a shared library / DLL . This function is meant to abstract access to shared libraries and DLLs and performs functions similar to dlopen () / dlsym () on Unix and LoadLibrary () / GetProcAddress () on Windows . If no support for loading entry points from a shared library is available this function will always return NULL . Rules on when this function issues a CPLError () or not are not currently well defined and will have to be resolved in the future . Currently CPLGetSymbol () doesn ' t try to : prevent the reference count on the library from going up for every request or given any opportunity to unload the library . Attempt to look for the library in non - standard locations . Attempt to try variations on the symbol name like pre - prending or post - pending an underscore . Some of these issues may be worked on in the future . @param pszLibrary the name of the shared library or DLL containing the function . May contain path to file . If not system supplies search paths will be used . @param pszSymbolName the name of the function to fetch a pointer to . @return A pointer to the function if found or NULL if the function isn ' t found or the shared library can ' t be loaded .
void *CPLGetSymbol( const char * pszLibrary, const char * pszSymbolName )
{
    void        *pLibrary;
    void        *pSymbol;
    pLibrary = dlopen(pszLibrary, RTLD_LAZY);
    if( pLibrary == NULL )
    {
        CPLError( CE_Failure, CPLE_AppDefined,
                  "%s", dlerror() );
        return NULL;
    }
    pSymbol = dlsym( pLibrary, pszSymbolName );
#if (defined(__APPLE__) && defined(__MACH__))
    if( pSymbol == NULL )
    {
        char withUnder[strlen(pszSymbolName) + 2];
        withUnder[0] = '_'; withUnder[1] = 0;
        strcat(withUnder, pszSymbolName);
        pSymbol = dlsym( pLibrary, withUnder );
    }
#endif
    if( pSymbol == NULL )
    {
        CPLError( CE_Failure, CPLE_AppDefined,
                  "%s", dlerror() );
        return NULL;
    }
    return( pSymbol );
}
void * CPLGetSymbol ( const char * pszLibrary , const char * pszSymbolName ) { void * pLibrary ; void * pSymbol ; pLibrary = dlopen ( pszLibrary , RTLD_LAZY ) ; if ( pLibrary == NULL ) { CPLError ( CE_Failure , CPLE_AppDefined , " " , dlerror ( ) ) ; return NULL ; } pSymbol = dlsym ( pLibrary , pszSymbolName ) ; #if ( defined ( __APPLE__ ) && defined ( __MACH__ ) ) if ( pSymbol == NULL ) { char withUnder [ strlen ( pszSymbolName ) + 2 ] ; withUnder [ 0 ] = ' ' ; withUnder [ 1 ] = 0 ; strcat ( withUnder , pszSymbolName ) ; pSymbol = dlsym ( pLibrary , withUnder ) ; } #endif if ( pSymbol == NULL ) { CPLError ( CE_Failure , CPLE_AppDefined , " " , dlerror ( ) ) ; return NULL ; } return ( pSymbol ) ; }
Fetch a function pointer from a shared library / DLL.
Fetch a function pointer from a shared library / DLL .
/* On mach-o systems, C symbols have a leading underscore and depending
     * on how dlcompat is configured it may or may not add the leading
     * underscore.  So if dlsym() fails add an underscore and try again.
     */