c调用动态库

tt posted @ 2007年11月15日 04:35 in C语言编程 , 2106 阅读

引自:http://linux.about.com/library/cmd/blcmdl3_dlsym.htm

#include <stdio.h>
#include <dlfcn.h>

int main(int argc, char **argv) {
void *handle;
double (*cosine)(double);
char *error;

handle = dlopen ("libm.so", RTLD_LAZY);
if (!handle) {
fprintf (stderr, "%s\n", dlerror());
return 1;
}
cosine = dlsym(handle, "cos");
if ((error = dlerror()) != NULL) {
fprintf (stderr, "%s\n", error);
return 1;
}
printf ("%f\n", (*cosine)(2.0));
dlclose(handle);
return 0;
}
编译命令如下:
   gcc -rdynamic -o foo foo.c -ldl
Avatar_small
celeb networth 说:
2022年11月18日 20:58

If you are interested in your favorite actors' net worth and detailed information, please take a look at celebrity networth database.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter