我从网上的一些例子中得到了这个小程序:
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
int
main(int argc, char **argv)
{
void *handle;
double (*cosine)(double);
char *error;
handle = dlopen("libzapi_v2.so.1", RTLD_LAZY);
if (!handle) {
printf("no handle \n");
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 the Rationale for the
POSIX specification of dlsym(). */
fprintf(stderr, "handle is here \n");
*(void **) (&cosine) = dlsym(handle, "cos");
if ((error = dlerror()) != NULL) {
fprintf(stderr, "%s\n", error);
exit(EXIT_FAILURE);
}
printf("%f\n", (*cosine)(2.0));
dlclose(handle);
exit(EXIT_SUCCESS);
}
我使用gcc -rdynamic -o np np.c编译它然后当我运行./np
我收到以下错误:
ld-elf.so.1:断言失败:/usr/src/libexec/rtld-elf/rtld.c:1046 中止(核心倾销)
我搜索并搜索了类似问题但找不到任何内容的人。有人可以提供一些故障排除建议吗?
这是最新的freebsd。