求助。。。。关于unix 动态链接库coredump的问题
小弟在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, 谢谢了!