"dmalloc.h:484:7: error: expected identifier or..." problem is already solved in that post.
Now let's compile and install a shared library
dmalloc-5.5.2]$ ./configure --enable-shlib
dmalloc-5.5.2]$ make shlib
...
gcc -g -O2 -DHAVE_STDARG_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_UNISTD_H=1 -DHAVE_SYS_MMAN_H=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_W32API_WINBASE_H=0 -DHAVE_W32API_WINDEF_H=0 -DHAVE_SYS_CYGWIN_H=0 -DHAVE_SIGNAL_H=1 -I. -I. -c dmalloc_argv.c -o ./dmalloc_argv.o
rm -f dmalloc
gcc -o aout dmalloc.o dmalloc_argv.o compat.o env.o \
-L.
mv aout dmalloc
rm -f libdmalloc.so libdmalloc.so.t
ld -shared --whole-archive -soname libdmalloc.so -o libdmalloc.so.t libdmalloc.a arg_check.o compat.o dmalloc_rand.o dmalloc_tab.o env.o heap.o chunk.o error.o malloc.o
ld: libdmalloc.a(arg_check.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
libdmalloc.a(arg_check.o): error adding symbols: Bad value
Makefile:259: recipe for target 'libdmalloc.so' failed
make: *** [libdmalloc.so] Error 1
Fix for the problem
alter the dmalloc-5.5.2/Makefile.in:
- 133 CCFLAGS = @CFLAGS@
- 133 CCFLAGS = @CFLAGS@
+ 133 CCFLAGS = @CFLAGS@ -fPIC
One more attempt...
dmalloc-5.5.2]$ ./configure --enable-shlib
dmalloc-5.5.2]$ make clean
rm -f aout core *.o *.t
rm -f libdmalloc.a libdmallocth.a libdmallocxx.a libdmallocthcxx.a dmalloc_t dmalloc_fc_t
rm -f libdmallocth.so libdmallocxx.so libdmallocthcxx.so libdmalloc.so
rm -f dmalloc dmalloc.h
dmalloc-5.5.2]$ make shlib
ranlib libdmalloc.a
rm -f libdmalloc.so libdmalloc.so.t
ld -shared --whole-archive -soname libdmalloc.so -o libdmalloc.so.t libdmalloc.a arg_check.o compat.o dmalloc_rand.o dmalloc_tab.o env.o heap.o chunk.o error.o malloc.o
arg_check.o: In function `_dmalloc_atoi':
dmalloc-5.5.2/arg_check.c:76: multiple definition of `_dmalloc_atoi'
libdmalloc.a(arg_check.o):dmalloc-5.5.2/arg_check.c:76: first defined here
arg_check.o: In function `_dmalloc_atol':
dmalloc-5.5.2/arg_check.c:92: multiple definition of `_dmalloc_atol'
...
dmalloc-5.5.2/malloc.c:2123: multiple definition of `dmalloc_get_stats'
libdmalloc.a(malloc.o):dmalloc-5.5.2/malloc.c:2123: first defined here
malloc.o: In function `dmalloc_strerror':
dmalloc-5.5.2/malloc.c:2151: multiple definition of `dmalloc_strerror'
libdmalloc.a(malloc.o):dmalloc-5.5.2/malloc.c:2151: first defined here
Makefile:259: recipe for target 'libdmalloc.so' failed
make: *** [libdmalloc.so] Error 1
Fix for the problem
ld -shared --whole-archive -soname libdmalloc.so -o libdmalloc.so.t libdmalloc.a arg_check.o compat.o dmalloc_rand.o dmalloc_tab.o env.o heap.o chunk.o error.o malloc.o
arg_check.o: In function `_dmalloc_atoi':
dmalloc-5.5.2/arg_check.c:76: multiple definition of `_dmalloc_atoi'
libdmalloc.a(arg_check.o):dmalloc-5.5.2/arg_check.c:76: first defined here
arg_check.o: In function `_dmalloc_atol':
dmalloc-5.5.2/arg_check.c:92: multiple definition of `_dmalloc_atol'
...
dmalloc-5.5.2/malloc.c:2123: multiple definition of `dmalloc_get_stats'
libdmalloc.a(malloc.o):dmalloc-5.5.2/malloc.c:2123: first defined here
malloc.o: In function `dmalloc_strerror':
dmalloc-5.5.2/malloc.c:2151: multiple definition of `dmalloc_strerror'
libdmalloc.a(malloc.o):dmalloc-5.5.2/malloc.c:2151: first defined here
Makefile:259: recipe for target 'libdmalloc.so' failed
make: *** [libdmalloc.so] Error 1
Fix for the problem
alter the dmalloc-5.5.2/Makefile.in:
- 260 @shlinkargs@ $(LIBRARY) $(OBJS) $(NORMAL_OBJS)
+ 260 @shlinkargs@ $(OBJS) $(NORMAL_OBJS) -lc
alter the dmalloc-5.5.2/configure:
- 4447 ac_cv_shared_link_args='ld -shared --whole-archive -soname $@ -o $@.t'
+ 4447 ac_cv_shared_link_args='$(CC) -shared -Wl,-soname,$@ -o $@.t'
Ok, let's try again...
dmalloc-5.5.2]$ ./configure --enable-shlib
dmalloc-5.5.2]$ make clean
rm -f aout core *.o *.t
rm -f libdmalloc.a libdmallocth.a libdmallocxx.a libdmallocthcxx.a dmalloc_t dmalloc_fc_t
rm -f libdmallocth.so libdmallocxx.so libdmallocthcxx.so libdmalloc.so
rm -f dmalloc dmalloc.h
dmalloc-5.5.2]$ make shlib
...
gcc -g -O2 -fPIC -DHAVE_STDARG_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_UNISTD_H=1 -DHAVE_SYS_MMAN_H=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_W32API_WINBASE_H=0 -DHAVE_W32API_WINDEF_H=0 -DHAVE_SYS_CYGWIN_H=0 -DHAVE_SIGNAL_H=1 -I. -I. -c malloc.c -o ./malloc.o
ar cr libdmalloc.a arg_check.o compat.o dmalloc_rand.o dmalloc_tab.o env.o heap.o chunk.o error.o malloc.o
ranlib libdmalloc.a
rm -f libdmalloc.so libdmalloc.so.t
gcc -shared -Wl,-soname,libdmalloc.so -o libdmalloc.so.t arg_check.o compat.o dmalloc_rand.o dmalloc_tab.o env.o heap.o chunk.o error.o malloc.o -lc
mv libdmalloc.so.t libdmalloc.so
Finally!! Let's check the library's dependencies
dmalloc-5.5.2]$ ldd -v libdmalloc.so
linux-vdso.so.1 => (0x00007fff11fe4000)
libc.so.6 => /lib64/libc.so.6 (0x00007fc0ed461000)
/lib64/ld-linux-x86-64.so.2 (0x00007fc0edb36000)
Version information:
./libdmalloc.so:
libc.so.6 (GLIBC_2.3) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.14) => /lib64/libc.so.6
libc.so.6 (GLIBC_2.2.5) => /lib64/libc.so.6
/lib64/libc.so.6:
ld-linux-x86-64.so.2 (GLIBC_2.3) => /lib64/ld-linux-x86-64.so.2
ld-linux-x86-64.so.2 (GLIBC_PRIVATE) => /lib64/ld-linux-x86-64.so.2
Installation
dmalloc-5.5.2-used]$ sudo make installsl
./mkinstalldirs /usr/local/lib
/usr/bin/install -c libdmalloc.so /usr/local/lib
Useful links
- Shared Libraries
No comments:
Post a Comment