Tuesday, January 12, 2016

dmalloc: compiling and installing a static library

dmallochttp://dmalloc.com/

Installation (on Fedora 21 x86_64)

$ uname -irs

Linux 3.18.3-201.fc21.x86_64 x86_64

$ tar -zxvf dmalloc-5.5.2.tgz
dmalloc-5.5.2]$ cd dmalloc-5.5.2/
dmalloc-5.5.2]$ ./configure
configure: configurations for the dmalloc library
configure: build utilities
checking for gcc... gcc
...
checking for strtok... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating conf.h
config.status: executing dmalloc.h.2 commands
config.status: executing settings.h commands
configure: 
configure: Please check-out Makefile and conf.h to make sure that
configure: sane configuration values were a result.
configure: 
configure: You may want to change values in settings.h before
configure: running 'make'.
configure: 
configure: To run the basic library tests, you can execute:
configure:   make light
configure: or
configure:   make heavy
configure:

dmalloc-5.5.2]$ make
rm -f dmalloc.h dmalloc.h.t
cat ./dmalloc.h.1 dmalloc.h.2 ./dmalloc.h.3 > dmalloc.h.t
mv dmalloc.h.t dmalloc.h
rm -f arg_check.o
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 arg_check.c -o ./arg_check.o
In file included from /usr/include/string.h:634:0,
                 from arg_check.c:33:
dmalloc.h:484:7: error: expected identifier or ‘(’ before ‘__extension__’
 char *strndup(const char *string, const DMALLOC_SIZE len);
       ^
Makefile:362: recipe for target 'arg_check.o' failed
make: *** [arg_check.o] Error 1


Found the similar problems:

- https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=633945
https://dev.openwrt.org/browser/packages/devel/dmalloc/patches/400-undef-strndup.patch?rev=31253
- http://stackoverflow.com/questions/1651886/programs-configured-to-use-dmalloc-bail-out-citing-header-file-error

Fixed it by altering dmalloc-5.5.2/dmalloc.h.3:

 - 432 | extern
 - 433 | char    *strndup(const char *string, const DMALLOC_SIZE len);

 + 432 | #undef strndup
 + 433 | extern
 + 434 | char    *strndup(const char *string, const DMALLOC_SIZE len);


Finishing installation

dmalloc-5.5.2]$ make
...
mv aout dmalloc
To make the thread version of the library type 'make threads'
To make the C++ version of the library type 'make cxx'
To make the shared version of the library type 'make shlib'

dmalloc-5.5.2]$ make light
...
mv aout dmalloc_fc_t
./dmalloc_fc_t -s
./dmalloc_t -s -t 10000
./dmalloc_t -s -t 10000
./dmalloc_t -s -t 10000
./dmalloc_t -s -t 10000
./dmalloc_t -s -t 10000
tests have passed

dmalloc-5.5.2]$ sudo make install
./mkinstalldirs /usr/local/include
/usr/bin/install -c -m 644 dmalloc.h /usr/local/include
./mkinstalldirs /usr/local/lib
/usr/bin/install -c libdmalloc.a /usr/local/lib
ranlib /usr/local/lib/libdmalloc.a
Enter 'make installsl' to install libdmalloc.so in /usr/local/lib
Enter 'make installcxx' to install the C++ library
Enter 'make installth' to install thread library
./mkinstalldirs /usr/local/bin
/usr/bin/install -c dmalloc /usr/local/bin
Enter 'make installdocs' to install dmalloc.html dmalloc.texi dmalloc.pdf in /usr/local/share/doc/dmalloc

No comments:

Post a Comment