dlopen 加载so库

#include   
#include   
  
int main(int argc, char **argv) {  
	void *handle;  
	double (*cosine)(double);  
	char *error;  
  
	handle = dlopen ("/tmp/libtest.so", RTLD_LAZY);  
	if (!handle) {  
		fprintf (stderr, "%s ", dlerror());  
		exit(1);  
	}  
  
	cosine = (double(*)(double))dlsym(handle, "cos");  
	if ((error = dlerror()) != NULL)  {  
		fprintf (stderr, "%s ", error);  
		exit(1);  
	}  
  
	printf ("%f ", (*cosine)(2.0));  
	dlclose(handle);  
	return 0;  
}  
 

  

你可能感兴趣的:(dlopen 加载so库)