/*************************************************************************** $name: DLFcn.c $version: 1.0 $date_modified: 030601 $description: Demonstrates use of dlfcn.h interfaces $owner: NKS Product Manager Copyright (c) 2001 Novell, Inc. All Rights Reserved. THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND TREATIES. USE AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO THE LICENSE AGREEMENT ACCOMPANYING THE SOFTWARE DEVELOPMENT KIT (SDK) THAT CONTAINS THIS WORK. PURSUANT TO THE SDK LICENSE AGREEMENT, NOVELL HEREBY GRANTS TO DEVELOPER A ROYALTY-FREE, NON-EXCLUSIVE LICENSE TO INCLUDE NOVELL'S SAMPLE CODE IN ITS PRODUCT. NOVELL GRANTS DEVELOPER WORLDWIDE DISTRIBUTION RIGHTS TO MARKET, DISTRIBUTE, OR SELL NOVELL'S SAMPLE CODE AS A COMPONENT OF DEVELOPER'S PRODUCTS. NOVELL SHALL HAVE NO OBLIGATIONS TO DEVELOPER OR DEVELOPER'S CUSTOMERS WITH RESPECT TO THIS CODE. ****************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <dlfcn.h> void *gDynLibHandle; char gDLLName[50] = "MyDynLib.NLM"; void cleanup_symbols( void ); void cleanup( void ) { // this will clean up all symbols from the library... dlclose(gDynLibHandle); } void main ( int argc, char **argv ) { int (*foo)( void ); // name the library of origin... gDynLibHandle = dlopen(gDLLName, RTLD_LOCAL); if (!gDynLibHandle) { printf("Unable to load dynamic library...\n"); exit(0); } atexit(cleanup); // get a symbol from that library... foo = dlsym(gDynLibHandle, "foo"); if (!foo) { printf("Failed to import 'foo': %s\n", dlerror()); exit(0); } }