Mailing List Archive

Support open source code!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Tcl/Tk ELF shared libs



Howdy all,

	Just thought I'd share a little... :)

	I was playing around with Tcl/Tk and decided I was going to
try to implement some stuff in the Tcl/Tk + C combination to increase
speed, etc.  I'd never done this, so I grabbed a file off of the Tcl
archive site that did a little Tk HelloWord example.  Well, initially
this file did not compile because it was written for the pre Tcl 7.x
days and there were some changes since then.  Well I looked through
some other code that came with the Tcl distribution and figured out
the problem and manager to compile the tkHelloWorld.

	Well, this little program that just is supposed to bring up a
window with a small button which, upon being clicked, exits the
program was 500+ K bytes.  As far as I was concerned, that wasn't
particularly efficient.  So I figured all I had to do was rebuild the
Tcl and Tk libs as shared libs and link them in as shared and things
would be smaller.  Sure, no problem *sarcasm intended*...

	Well, to my utter astonishment, it actually wasn't a problem.
I did the following:

1.  untarred the Tcl and Tk sources as per the installation
instructions.

2.  did ./configure

3.  changed the CFLAGS variable from "-O" to "-O -fPIC" in the Makefile

4.  did a make

5.  did a "gcc -shared -Wl,-soname,libtcl.so.7 -o libtcl.so.7.4 *.o"
      and "gcc -shared -Wl,-soname,libtk.so.4 -o libtk.so.4.0 *.o" in
their appropriate directories

6.  and there they were libtcl.so.7.4 and libtk.so.4.0, so I moved
them to /usr/local/lib

7.  did a /sbin/ldconfig    (after making sure that /usr/local/lib was
in my /etc/ldconfig.so.conf file)


	Then, I rebuilt the tkHelloWorld program and it was down to
5688 bytes (stripped), a bit better. :)

	Feeling particularly adventurous, I decided I could do the
same for tclsh and wish.  So I did and knocked them down to 5540 for
wish and 3220 for tclsh, instead or some number of hundreds of k.  The
only thing I had to do for those executable was this:

	When the make is finished, check out the last command run, for
me it was:

cc -O -fPIC -I. -I./../tcl7.4 -I/usr/X11R6/include -DHAVE_UNISTD_H=1
-DHAVE_LIMITS_H=1 -DSTDC_HEADERS=1 -DTK_FILE_READ_PTR=1
-DTK_LIBRARY=\"/usr/local/lib/tk4.0\" tkAppInit.o libtk.a
../tcl7.4/libtcl.a -L/usr/X11R6/lib -lX11  -lieee -lm -o wish


I just copied it, but changing it to:

cc -O -fPIC -I. -I./../tcl7.4 -I/usr/X11R6/include -DHAVE_UNISTD_H=1
-DHAVE_LIMITS_H=1 -DSTDC_HEADERS=1 -DTK_FILE_READ_PTR=1
-DTK_LIBRARY=\"/usr/local/lib/tk4.0\" tkAppInit.o -ltk
-ltcl -L/usr/X11R6/lib -lX11  -lieee -lm -o wish
     

	Of course I had to create and install the shared Tcl and Tk
libs first.  The only drawback of this whole operation is that my
tkHelloWorld executable requires a system that has shared libraries as
well.  Also, this could have been done in the Makefile more
appropriately, but I was on a roll.  :)

	One last thing...I noticed that when I compiled the
tkHelloWorld, I did not change and flags to make it shared.  It seems
that the gcc linked will default to shared if those libraries are
available and, if not, will create it as staticly linked in.


	Well, there you go, fun with Linux...


_________________________________________________________________________
FORE Systems Japan, Inc.			     3-1-4 Nishi-Shinjuku
Rainer Mager - Systems Engineer		     Shinjuku-ku, Tokyo 160 Japan
TEL:  81-3-3346-2781		rvm@example.com	     FAX:  81-3-3346-2782



Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links