小编Rah*_*wal的帖子

如何使用静态库 libdl.a 编译程序

我正在尝试编译使用 libdl 库中的 API 的示例代码:

#include <stdio.h>
#include <stdlib.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());
        exit(EXIT_FAILURE);
    }

   dlerror();    /* Clear any existing error */

   /* Writing: cosine = (double (*)(double)) dlsym(handle, "cos");
       would seem more natural, but the C99 standard leaves
       casting from "void *" to a function pointer undefined.
       The assignment used below is the POSIX.1-2003 (Technical
       Corrigendum 1) workaround; see …
Run Code Online (Sandbox Code Playgroud)

c gcc libc

5
推荐指数
1
解决办法
3958
查看次数

标签 统计

c ×1

gcc ×1

libc ×1