求助。。。。关于unix 动态链接库coredump的问题
时间:2010-06-19
来源:互联网
小弟在unix下写动态链接库,仿照网上很多例子来写的,但是到最后总是出现coredump, 希望各位高手们帮小弟解决下这个问题。
/*****************explicit.c ******************/
#include<stdio.h>
#include<dlfcn.h>
int main(int argc,char* argv[])
{
int a = 10;
int b = 20;
int sum = 0;
int(*pSum)();
printf("a=[%d],b=[%d],sum=[%d]\n",a,b,sum);
void *pdlHandle;
char* pdlErr;
printf("open so......\n");
pdlHandle = dlopen("./lib/libtest.so",RTLD_LAZY);
if(!pdlHandle)
{
printf("open dynamic library failed\n");
}
pdlErr = dlerror();
if(pdlErr != NULL)
{
printf("%s\n",pdlErr);
return 0;
}
printf("getting from so....\n");
pSum = (int(*)())dlsym(pdlHandle,"retResult");
pdlErr = dlerror();
if(pdlErr != NULL)
{
printf("%sn", pdlErr);
dlclose(pdlHandle);
return 0;
}
printf("got it!\n");
sum = pSum(a,b);
printf("calling success.........\n");
printf("The sum of a and b is ==== [%d]\n",sum);
dlclose(pdlHandle);
return 0;
/*********************************************************************/
函数指针可能会有点问题,但是绝对不是真正的问题所在,因为我尝试过void类型的,也会coredump。
retResult函数原型很简单,就是输出一句话,返回一个a+b。
编译库的make_lib:
all:libtest.so
CC=cc -q64 -qcpluscmt -g
.c.o:
$(CC) -c -Kpic $<
build_command:
$(CC) -G $(OBJS) -o ./lib/$(DLL)
all_objs=test.o
libtest.so:$(all_objs)
make -f ./make_lib OBJS="$(all_objs)" DLL=$@ build_command
操作系统:AIX
错误信息如下:
a=[10],b=[20],sum=[0]
open so......
getting from so....
got it!
Illegal instruction(coredump);
在线等答复~~~~~也可以加我qq 251157654, 谢谢了!
/*****************explicit.c ******************/
#include<stdio.h>
#include<dlfcn.h>
int main(int argc,char* argv[])
{
int a = 10;
int b = 20;
int sum = 0;
int(*pSum)();
printf("a=[%d],b=[%d],sum=[%d]\n",a,b,sum);
void *pdlHandle;
char* pdlErr;
printf("open so......\n");
pdlHandle = dlopen("./lib/libtest.so",RTLD_LAZY);
if(!pdlHandle)
{
printf("open dynamic library failed\n");
}
pdlErr = dlerror();
if(pdlErr != NULL)
{
printf("%s\n",pdlErr);
return 0;
}
printf("getting from so....\n");
pSum = (int(*)())dlsym(pdlHandle,"retResult");
pdlErr = dlerror();
if(pdlErr != NULL)
{
printf("%sn", pdlErr);
dlclose(pdlHandle);
return 0;
}
printf("got it!\n");
sum = pSum(a,b);
printf("calling success.........\n");
printf("The sum of a and b is ==== [%d]\n",sum);
dlclose(pdlHandle);
return 0;
/*********************************************************************/
函数指针可能会有点问题,但是绝对不是真正的问题所在,因为我尝试过void类型的,也会coredump。
retResult函数原型很简单,就是输出一句话,返回一个a+b。
编译库的make_lib:
all:libtest.so
CC=cc -q64 -qcpluscmt -g
.c.o:
$(CC) -c -Kpic $<
build_command:
$(CC) -G $(OBJS) -o ./lib/$(DLL)
all_objs=test.o
libtest.so:$(all_objs)
make -f ./make_lib OBJS="$(all_objs)" DLL=$@ build_command
操作系统:AIX
错误信息如下:
a=[10],b=[20],sum=[0]
open so......
getting from so....
got it!
Illegal instruction(coredump);
在线等答复~~~~~也可以加我qq 251157654, 谢谢了!
作者: superniyue 发布时间: 2010-06-19
pSum = (int(*)())dlsym(pdlHandle,"retResult");
==》
pSum = (int(*)(int,int))dlsym(pdlHandle,"retResult");
==》
pSum = (int(*)(int,int))dlsym(pdlHandle,"retResult");
作者: hqin6 发布时间: 2010-06-19
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28