编动态链接库时,提示 对‘dlopen’未定义的引用.该如何解决

编动态链接库时,提示 对‘dlopen’未定义的引用.
我按网上的方法写了个调用LINUX下的动态链接库的代码。代码如下。
#include   <iostream>
#include   <dlfcn.h>
using   namespace   std;

int   main()
{
  void   *dp;

  dp   =   dlopen( "test.so ",RTLD_NOW);
  if   (dp==NULL)
  {
    fputs(dlerror(),stderr);
    exit(1);
  }

  dlclose(dp);
  return   0;
}

编译时报错:
../main.cpp:9:对 'dlopen '未定义的引用
../main.cpp:12:对 'dlerror '未定义的引用
../main.cpp:16:对 'dlclose '未定义的引用
collect2:   ld   returned   1   exit   status
...
...

我用的编程环境   ubunto   +   eclipse3.2   +   cdt3.1.1
我用g++编译也是一样的错误.
是不是没有引对   dlfcn.h   ,但我设置的时候   也设了的阿...

请教高手是什么原因.

------解决方案--------------------
-ldl
===
mymtom@fc6:src/csdn/dlopen$ make LDLIBS=-ldl dlopen
g++ dlopen.cpp -ldl -o dlopen
mymtom@fc6:src/csdn/dlopen$ cat dlopen.cpp
#include <iostream>
#include <dlfcn.h>
using namespace std;

int main()
{
void *dp;

dp = dlopen( "test.so ",RTLD_NOW);
if (dp==NULL)
{
fputs(dlerror(),stderr);
exit(1);
}

dlclose(dp);
return 0;
}

mymtom@fc6:src/csdn/dlopen$ uname -a
Linux fc6.unix-center.net 2.6.18-1.2798.fc6 #1 SMP Mon Oct 16 14:39:22 EDT 2006 x86_64
mymtom@fc6:src/csdn/dlopen$
------解决方案--------------------
make file 加上 -ldl
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值