c++ - Linux c++错误: undefined reference to 'dlopen'

标签 c++ linux eclipse

我使用 C++ (Eclipse) 在 Linux 中工作,并且想使用一个库。 Eclipse 显示错误:

undefined reference to 'dlopen' 

您知道解决方案吗?

这是我的代码:

#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");

    if ((error = dlerror()) != NULL)  {
        fputs(error, stderr);
        exit(1);
    }

    dlclose(handle);
}

最佳答案

你必须链接libdl,添加

-ldl

到您的链接器选项

关于c++ - Linux c++错误: undefined reference to 'dlopen' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/956640/

相关文章:

eclipse - ALT+CMD+R 停止工作

c++ - 具有私有(private)构造函数的 unordered_map 值类型

c++ - 为什么 c 中地址的值总是偶数?

linux - 如何查找进程打不开的文件夹

linux - 具有多个变量(语句)的循环

linux - “查找”包含指定范围内整数的文件(在 bash 中)

java - 无法在 Eclipse 工作区中配置 Web 应用程序项目的运行路径

c++ - 如何构建程序,以便在 EXE ( CodeBlocks ) 位置不需要 DLL

c++ - 为什么可以将整数类型转换为指针?

java - Eclipse Helios 的自定义 Java 代码折叠