我使用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);
}
发布于 2014-04-11 02:24:45
@Masci是正确的,但如果您使用C(和gcc
编译器),请考虑到这不起作用:
gcc -ldl dlopentest.c
但这确实是:
gcc dlopentest.c -ldl
我花了点时间才弄明白...
发布于 2019-03-28 05:31:12
我在使用CMake编译我的项目时发现了同样的问题。
描述here的解决方案工作起来很棒,只需将${CMAKE_DL_LIBS}添加到target_link_libraries()调用中
发布于 2014-07-06 18:28:45
这个话题很老了,但我今天在编译cegui 0.7.1 (openVibe先决条件)时遇到了同样的问题。
对我起作用的是在Makefile中设置:LDFLAGS="-Wl,--no-as-needed"
。
我也尝试过用于LDFLAGS
的-ldl
,但没有效果。
https://stackoverflow.com/questions/956640
复制相似问题