免费注册 查看新帖 |

Chinaunix

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

紧急求助.about gcc on solaris [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-01-22 16:49 |只看该作者 |倒序浏览
先谢过大家看我的贴子.我遇到的问题如下:

我用了一个测试程序,测试UNIX下的shared object的调用.这个程序在cygwin/linux/
unixware下都调用成功.就是在SUN OS5.8里不行.各位请看看是怎么回事.
-----------------------------------------------------------------------------------------
dlTest.c (主程序)
-----------------------------------------------------------------------------------------
/**********************************************************/
/* Test UNIX Dynamic Function Loading */
/* */
/* void *dlopen(const char *filename, int flag) */
/* Opens dynamic library and return handle */
/* */
/* const char *dlerror(void) */
/* Returns string describing the last error. */
/* */
/* void *dlsym(void *handle, char *symbol) */
/* Return pointer to symbol\'s load point. */
/* If symbol is undefined, NULL is returned. */
/* */
/* int dlclose (void *handle) */
/* Close the dynamic library handle. */
/* */
/**********************************************************/
#include <stdio.h>
#include <stdlib.h>

/* 1-dll include file and variables */
#include <dlfcn.h>
#include <link.h>

void *FunctionLib; /* Handle to shared lib file */
int (*Function)(); /* Pointer to loaded routine */
const char *dlError; /* Pointer to error string */

int main( int argc, char* argv )
{
int rc; /* return codes */
char HelloMessage[] = \"HeLlO WoRlD\\n\";

/* 2-print the original message */
printf(\" dlTest 2-Original message \\n\";
printf(\"%s\", HelloMessage);

/* 3-Open Dynamic Loadable Libary with absolute path */
FunctionLib = dlopen(\"/eitop/switch/test/so/bin/UPPERCASE.so\", RTLD_LAZY);
dlError = dlerror();
printf(\" dlTest 3-Open Library with absolute path return-%s- \\n\", dlError);
if( dlError ) exit(1);

/* 4-Find the first loaded function */
Function = dlsym( FunctionLib, \"printUPPERCASE\";
dlError = dlerror();
printf(\" dlTest 4-Find symbol printUPPERCASE return-%s- \\n\", dlError);
if( dlError ) exit(1);

/* 5-Execute the first loaded function */
rc = (*Function)( HelloMessage );
printf(\" dlTest 5-printUPPERCASE return-%s- \\n\", dlError);

/* 6-Close the shared library handle */
/* Note: after the dlclose, \"printUPPERCASE\" is not loaded */
rc = dlclose(FunctionLib);
dlError = dlerror();
printf(\" dlTest 6-Close handle return-%s-\\n\",dlError);
if( rc ) exit(1);


/* 7-Open Dynamic Loadable Libary using LD_LIBRARY path */
FunctionLib = dlopen(\"lowercase.so\",RTLD_LAZY);
dlError = dlerror();
printf(\" dlTest 7-Open Library with relative path return-%s- \\n\", dlError);
if( dlError ) exit(1);

/* 8-Find the second loaded function */
Function = dlsym( FunctionLib, \"printLowercase\";
dlError = dlerror();
printf(\" dlTest 8-Find symbol printLowercase return-%s- \\n\", dlError);
if( dlError ) exit(1);

/* 8-execute the second loaded function */
rc = (*Function)( HelloMessage );
printf(\" dlTest 9-printLowercase return-%s- \\n\", dlError);

/* 10-Close the shared library handle */
rc = dlclose(FunctionLib);
dlError = dlerror();
printf(\" dlTest 10-Close handle return-%s-\\n\",dlError);
if( rc ) exit(1);

return(0);

}

-----------------------------------------------------------------------------------------
lowercase.c (被编译成lowercase.so的程序)
-----------------------------------------------------------------------------------------
/********************************************/
/* Function to print input string as lower case. */
/* Returns 2. */
/******************************************* */
int printLowercase( inLine )
char inLine[];
{
char lowstring[256];
char *inptr, *outptr;
inptr = inLine;
outptr = lowstring;
while ( *inptr != \'\\0\' )
*outptr++ = tolower(*inptr++);
*outptr++ = \'\\0\';
printf(lowstring);
return(2);
}

-----------------------------------------------------------------------------------------
UPPERCASE.c (被编译成UPPERCASE.so的程序)
-----------------------------------------------------------------------------------------
/************************************************/
/* Function to print input string as UPPER case. */
/* Returns 1. */
/*********************************************** */

int printUPPERCASE ( inLine )
char inLine[];
{
char UPstring[256];
char *inptr, *outptr;

inptr = inLine;
outptr = UPstring;
while ( *inptr != \'\\0\' )
*outptr++ = toupper(*inptr++);
*outptr++ = \'\\0\';
printf(UPstring);
return(1);
}

-----------------------------------------------------------------------------------------
Makefile
-----------------------------------------------------------------------------------------
########################################################
# test shared object in solaris
#
WORKDIR = $(HOME)/test/so
INCDIR = $(WORKDIR)
LIBDIR = /usr/local/lib
DLLDIR = $(WORKDIR)/bin
BINDIR = $(WORKDIR)/bin
USRINCL = -I$(INCDIR)
USRLIBS = -L$(LIBDIR) -ldl -lm
CC = gcc
CPP = gcc
CCFLAGS = -c
DLLFLAGS = -fPIC
MKDLL = $(CC) -fPIC -shared -lc
DELE = rm -f

ALL:clean dlTest UPPERCASE.so lowercase.so cleantmp

clean:
$(DELE) *.o
$(DELE) $(DLLDIR)/*.so
$(DELE) $(BINDIR)/dlTest

cleantmp:
$(DELE) *.o

dlTest.o:
$(CC) $(CCFLAGS) dlTest.c

lowercase.o:
$(CC) $(CCFLAGS) $(DLLFLAGS) lowercase.c

UPPERCASE.o:
$(CC) $(CCFLAGS) $(DLLFLAGS) UPPERCASE.c

lowercase.so:lowercase.o
$(MKDLL) -o $(DLLDIR)/lowercase.so lowercase.o

UPPERCASE.so:UPPERCASE.o
$(MKDLL) -o $(DLLDIR)/UPPERCASE.so UPPERCASE.o

dlTest:dlTest.o
$(CC) -o $(BINDIR)/dlTest $(USRLIBS) $(USRINCL) dlTest.o

-------------------------------------------------------------------------------------------
问题:
在Solaris下用gcc 编译后.dlTest程序每当运行到dlopen时就core dump了.
为什么?

再次谢过了.

论坛徽章:
0
2 [报告]
发表于 2003-01-22 16:50 |只看该作者

my gcc version

我的gcc版本如下:
$gcc -v
Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.1/specs
Configured with: ../configure --with-as=/usr/ccs/bin/as --with-ld=/usr/ccs/bin/ld --disable-nls
Thread model: posix
gcc version 3.1

论坛徽章:
0
3 [报告]
发表于 2003-01-23 08:39 |只看该作者
Most of times core dump is resulted from segment error. Possible reasons are null pointer and out of memory. For dynamic load library in Solaris with GCC, the compiler does not check the resolution of library path. If there is a lib error, it can be found only when it is executed. Check the system libray path, update make file and retry it again.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP