gpt4 book ai didi

c++ - 在 Linux 中使用 C++ 库 (eclipse)

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:32:26 25 4
gpt4 key购买 nike

我写了一个库,想测试一下。我写了下面的程序,但是我从 eclipse 收到一条错误消息。

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

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

handle = dlopen ("/lib/CEDD_LIB.so.6", RTLD_LAZY);
if (!handle) {
fputs (dlerror(), stderr);
exit(1);
}

desk= dlsym(handle, "Apply"); // ERROR: cannot convert from 'void *' to 'double*(*)(char*)' for argument 1
if ((error = dlerror()) != NULL) {
fputs(error, stderr);
exit(1);
}

dlclose(handle);
}

怎么了?

问候。

最佳答案

在 C++ 中,您需要以下内容:


typedef double (*func)(char*);
func desk = reinterpret_cast<func>( dlsym(handle, "Apply"));

关于c++ - 在 Linux 中使用 C++ 库 (eclipse),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/956284/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com