免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1825 | 回复: 3
打印 上一主题 下一主题

HP 下的动态链接库的实现问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-02-08 07:56 |只看该作者 |倒序浏览
我在用户的要求下要把系统改为动态加载工作包 可以在做动态库的时候,遇到了如下问题,请高手帮忙解决。
在HP unix 用aCC编译
hello.cpp

#include<stdio.h>;
int printHello()
{
      printf("hello world !\n";
      return 1;
}

aCC -d -o hello.sl hello.cpp


main.cpp

int main()
{
      int (*iRtn)() ;
      void* hello;
      
      hello = dlopen("./hello.sl",RTLD_LAZY);
      if (hello == NULL)
      {
           printf("1 you are wrong !\n";
           return 0;
      }
     
      iRtn = (int(*)())dlsym(hello ,"printHello";
      if (iRtn == NULL)
      {
           printf("2 you are wrong !\n";
           return 0;
      }
      (*iRtn)();
      return 1;
}
  aCC  -o main main.cpp  

以上方法编译后,运行的结果是printf("2 you are wrong !\n";

为什么不能指定sl下的函数位置呢?

论坛徽章:
0
2 [报告]
发表于 2004-02-11 14:44 |只看该作者

HP 下的动态链接库的实现问题

dumpbin 看看 hello.sl里的export符号先。
没有用过acc不知道acc生成sl文件是不是这样做的,不过c++程序的函数名
一些编译器在导出时名字都是处理过了的,和程序里的不一样。

论坛徽章:
0
3 [报告]
发表于 2004-05-13 20:53 |只看该作者

HP 下的动态链接库的实现问题

动态库程序hello.cpp 中要声明库里的函数

论坛徽章:
0
4 [报告]
发表于 2004-07-20 12:10 |只看该作者

HP 下的动态链接库的实现问题

在hello.cpp中加

extern "c"
{
int printHello() ;
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP