Operating System - HP-UX
1828206 Members
2108 Online
109975 Solutions
New Discussion

Compilation of shared library

 
svilen888
Occasional Advisor

Compilation of shared library

I'm trying to compilate a small shared
library and use it:
1.Sources:
sss.c: void sss(char ss)
{ putchar(ss); }
ssss.c: void ssss()
{ printf("Message!"); }
filtest.c:
#include
#include
#include
#include

char b[224];

int main(argc, argv)
int argc;
char **argv;
{ char c;
int i;
int fin;
if (argc == 1) {
printf("No file name.\n");
return 1;
}
fin=open(argv[1], O_RDONLY);
if (fin == NULL) {
printf("%s\n", strerror(errno));
return 1;
}
lseek(fin, 5, 0);
i = read(fin, &b, 10);
if (i != 10) {
printf("%s\n", strerror(errno));
return 1;
}
if (close(fin) != 0) {
printf("%s\n", strerror(errno));
return 1;
}
for (i = 0; i < 224; i++) {
if (i%16 == 0) putchar('\n');
sss(b[i+2]);
}
ssss();
return 0;
}

2.Compilation sl-library:
#gcc -c -ansi -shared ./sss.c
#gcc -c -ansi -shared ./ssss.c
#ld -b -o libmy.sl sss.o ssss.o
Then I move libmy.sl in /usr/lib with
right permissions.
And: /etc/SHLIB_PATH = /usr/lib: ...
3.Compilation main program filtest.c:
#gcc -g -lmy ./filtest.c
4.Using:
#./a.out somefile

memory fault(coredump).
5.Debugging
#gdb ./a.out ./core

This GDB was configured as "hppa1.1-
hp-hpux10.20"...
Core was generated by `a.out'.
Program terminated with signal 11,
Segmentation fault.
warning: The shared libraries were not
privately mapped; setting a
breakpoint in a shared library will not
work until you rerun the program.

Reading symbols from ./a.out...done.
Reading symbols
from /usr/lib/libmy.sl...done.
Reading symbols
from /usr/lib/libc.1...done.
Reading symbols
from /usr/lib/libdld.1...done.
#0 0xc0bb51f0 in ?? ()
from /usr/lib/libmy.sl
(gdb) bt
#0 0xc0bb51f0 in ?? ()
from /usr/lib/libmy.sl
Memory fault(coredump)

Please help me to understand this
situation?
Liana
liana
1 REPLY 1
Stanimir
Trusted Contributor

Re: Compilation of shared library


Wrong compilation!
Try:

#gcc -c -fpic ./sss.c ./ssss.c
#ld -b -o libmy.sl sss.o ssss.o

Stan