Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Adding readline support for tclsh

Has anyone in this forum successfully added readline support for the TCL shell (tclsh)?

None of the suggestions for tclreadline here <http://wiki.tcl.tk/5632> have helped.

I've downloaded and installed readline-6.1:


...rs/chap/Downloads/readline-6.1$ sudo make install
Password:
/bin/sh ./support/mkinstalldirs /usr/local/include
/usr/local/include/readline /usr/local/lib
/usr/local/share/info /usr/local/share/man/man3
for f in readline.h chardefs.h keymaps.h history.h tilde.h rlstdc.h rlconf.h rltypedefs.h; do
/usr/bin/install -c -m 644 ./$f /usr/local/include/readline ;
done
( if test -d doc ; then
cd doc &&
make infodir=/usr/local/share/info DESTDIR= install;
fi )
/bin/sh ../support/mkdirs /usr/local/share/info /usr/local/share/man/man3
if test -n "" ; then
/bin/sh ../support/mkdirs ;
fi
if test -f readline.info; then
/usr/bin/install -c -m 644 readline.info /usr/local/share/info/readline.info;
else
/usr/bin/install -c -m 644 ./readline.info /usr/local/share/info/readline.info;
fi
if test -f rluserman.info; then
/usr/bin/install -c -m 644 rluserman.info /usr/local/share/info/rluserman.info;
else
/usr/bin/install -c -m 644 ./rluserman.info /usr/local/share/info/rluserman.info;
fi
if test -f history.info; then
/usr/bin/install -c -m 644 history.info /usr/local/share/info/history.info;
else
/usr/bin/install -c -m 644 ./history.info /usr/local/share/info/history.info;
fi
if /bin/sh -c 'install-info --version' >/dev/null 2>&1; then
install-info --dir-file=/usr/local/share/info/dir
/usr/local/share/info/readline.info ;
install-info --dir-file=/usr/local/share/info/dir
/usr/local/share/info/history.info ;
install-info --dir-file=/usr/local/share/info/dir
/usr/local/share/info/rluserman.info ;
else true; fi
/usr/bin/install -c -m 644 ./readline.3 /usr/local/share/man/man3/readline.3
/usr/bin/install -c -m 644 ./history.3 /usr/local/share/man/man3/history.3
if test -n "" ; then
if test -f readline.html; then
/usr/bin/install -c -m 644 readline.html /readline.html;
else
/usr/bin/install -c -m 644 ./readline.html /readline.html;
fi ;
if test -f history.html; then
/usr/bin/install -c -m 644 history.html /history.html;
else
/usr/bin/install -c -m 644 ./history.html /history.html;
fi ;
if test -f rluserman.html; then
/usr/bin/install -c -m 644 rluserman.html /rluserman.html;
else
/usr/bin/install -c -m 644 ./rluserman.html /rluserman.html;
fi ;
fi
test -d shlib || mkdir shlib
( cd shlib ; make all )
make[1]: Nothing to be done for `all'.
( cd examples ; make DESTDIR= install )
/bin/sh ../support/mkdirs /usr/local/share/readline
mv /usr/local/lib/libreadline.a /usr/local/lib/libreadline.old
/usr/bin/install -c -m 644 libreadline.a /usr/local/lib/libreadline.a
test -n "ranlib" && ranlib /usr/local/lib/libreadline.a
mv /usr/local/lib/libhistory.a /usr/local/lib/libhistory.old
/usr/bin/install -c -m 644 libhistory.a /usr/local/lib/libhistory.a
test -n "ranlib" && ranlib /usr/local/lib/libhistory.a
( cd shlib ; make DESTDIR= install )
/bin/sh ../support/mkdirs /usr/local/lib
/bin/sh ../support/shlib-install -O darwin10.2.0 -V apple -d /usr/local/lib -b /usr/local/bin -i "/usr/bin/install -c -m 644" libhistory.6.1.dylib
/bin/sh ../support/shlib-install -O darwin10.2.0 -V apple -d /usr/local/lib -b /usr/local/bin -i "/usr/bin/install -c -m 644" libreadline.6.1.dylib
install: you may need to run ldconfig


(No idea what ldconfig is...)

I've even tried installing rlwrap, with these errors:


gcc -DDATADIR="/usr/local/share" -g -O2 -o rlwrap main.o signals.o readline.o pty.o completion.o term.o ptytty.o utils.o string_utils.o malloc_debug.o filter.o -lutil -lreadline -lcurses
Undefined symbols:
"rl_expandprompt", referenced from:
restore_rlstate in readline.o
"rl_deletetext", referenced from:
linehandler in readline.o
save_rlstate in readline.o
munge_line_ineditor in readline.o
"rl_dumpfunctions", referenced from:
dump_allkeybindings in readline.o
"rl_variabledumper", referenced from:
dump_allkeybindings in readline.o
"_rl_horizontal_scrollmode", referenced from:
prompt_is_singleline in readline.o
"rl_macrodumper", referenced from:
dump_allkeybindings in readline.o
"rl_on_newline", referenced from:
adapt_ttywinsize in signals.o
"rl_get_keymap_byname", referenced from:
_bindkey in readline.o
"rl_variablevalue", referenced from:
prompt_is_singleline in readline.o
"rl_catchsigwinch", referenced from:
initreadline in readline.o
"rl_basic_quotecharacters", referenced from:
_main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status


I'm kind of an intermediate beginner with Unix install procedures, and I really don't know what I'm doing at this point. Any suggestions?

Thanks,
Chap

2.4GHz MacBook Pro, Mac OS X (10.6), /Developer

Posted on Jan 19, 2010 11:50 AM

Reply
6 replies

Jan 19, 2010 5:06 PM in response to Chap Harrison

Chap Harrison wrote:
Has anyone in this forum successfully added readline support for the TCL shell (tclsh)?


Can you tell me why I would want to?

(No idea what ldconfig is...)


It is a Linux thing. Don't worry about it. You don't need it.

I've even tried installing rlwrap, with these errors:


Does this mean that rlwrap was a last-ditch effort? Your readline build seems to have worked fine. You really didn't say anything about build tclreadline.


gcc -DDATADIR="/usr/local/share" -g -O2 -o rlwrap main.o signals.o readline.o pty.o completion.o term.o ptytty.o utils.o string_utils.o malloc_debug.o filter.o -lutil -lreadline -lcurses
Undefined symbols:
"rl_expandprompt", referenced from:
restore_rlstate in readline.o
"rl_deletetext", referenced from:
linehandler in readline.o
save_rlstate in readline.o
munge_line_ineditor in readline.o
"rl_dumpfunctions", referenced from:
dump_allkeybindings in readline.o
"rl_variabledumper", referenced from:
dump_allkeybindings in readline.o
"_rl_horizontal_scrollmode", referenced from:
prompt_is_singleline in readline.o
"rl_macrodumper", referenced from:
dump_allkeybindings in readline.o
"rl_on_newline", referenced from:
adapt_ttywinsize in signals.o
"rl_get_keymap_byname", referenced from:
_bindkey in readline.o
"rl_variablevalue", referenced from:
prompt_is_singleline in readline.o
"rl_catchsigwinch", referenced from:
initreadline in readline.o
"rl_basic_quotecharacters", referenced from:
_main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status


I'm kind of an intermediate beginner with Unix install procedures, and I really don't know what I'm doing at this point. Any suggestions?


There is already a system "readline" in /usr/lib (although it really isn't readline) and the system is using that instead of your readline in /usr/local/lib. There are a number of ways to fix this. I just changed "-lreadline" in the makefile to "-lreadline.6.1" and that did the trick. It isn't the most elegant solution, but then I'm not sure rlwrap is your preferred solution.

Perhaps you can enlighten me on what your final goal is.

Jan 19, 2010 5:26 PM in response to etresoft

etresoft wrote:
Chap Harrison wrote:
Has anyone in this forum successfully added readline support for the TCL shell (tclsh)?


Can you tell me why I would want to?


I can tell you why I want to 😉

I want to run the shell interactively, in order to learn / try out things in TCL.

All towards the goal of writing some Expect scripts.

I've even tried installing rlwrap, with these errors:


Does this mean that rlwrap was a last-ditch effort? Your readline build seems to have worked fine. You really didn't say anything about build tclreadline.


rlwrap was a last-ditch effort, yes. From what I read, 'rlwrap <program>' will provide readline capability to <program>'s STDIN. All I really want is history retrieval and command line editing.


There is already a system "readline" in /usr/lib (although it really isn't readline) and the system is using that instead of your readline in /usr/local/lib.


Yup. That was pretty confusing.

There are a number of ways to fix this. I just changed "-lreadline" in the makefile to "-lreadline.6.1" and that did the trick.


I'll give that a try.

It isn't the most elegant solution, but then I'm not sure rlwrap is your preferred solution.


rlwrap is only last-ditch. The Installing the TCL tclreadline package (which requires GNU readline) would be the preferred solution.

Jan 19, 2010 5:34 PM in response to Chap Harrison

Chap Harrison wrote:
I want to run the shell interactively, in order to learn / try out things in TCL.

All towards the goal of writing some Expect scripts.


Fair enough. I always want to ask to make sure there isn't some super-easy solution to the real problem.

rlwrap is only last-ditch. The Installing the TCL tclreadline package (which requires GNU readline) would be the preferred solution.


Perhaps you should re-focus on that. The tclreadline package seems to build fine. What problems are you having?

Jan 19, 2010 9:44 PM in response to etresoft

Okay: the official writeup at sourceforge is http://tclreadline.sourceforge.net/

Here's a salient excerpt:

If you want to use tclreadline as a line interface for developing tcl scripts, you probably don't have to read much of the following section. Just install the package and put the following lines to your $HOME/.tclshrc:
if {$tcl_interactive} {
package require tclreadline
::tclreadline::Loop
}

The wording there is ambiguous to me ("...as a line interface for developing tcl scripts..."). I hope the author means "to add crunchy readline goodness to tclsh's horrible command line interface." I'll assume he does.

So, I created *~/.tclshrc* and added the required code, and then, from Terminal, entered

*/Users/chap/Downloads$* tclsh -i
dlopen(/usr/lib/libtclreadline.dylib, 10): image not found

Here is the output from the build and install of tclreadline:


...ap/Downloads/tclreadline-2.1.0$ ./configure
loading cache ./config.cache
checking for a BSD compatible install... (cached) /usr/bin/install -c
checking whether build environment is sane... yes
checking whether make sets ${MAKE}... (cached) yes
checking for working aclocal... found
checking for working autoconf... found
checking for working automake... found
checking for working autoheader... found
checking for working makeinfo... found
checking whether make sets ${MAKE}... (cached) yes
checking host system type... i386-apple-darwin10.2.0
checking for gcc... (cached) gcc
checking whether the C compiler (gcc ) works... yes
checking whether the C compiler (gcc ) is a cross-compiler... no
checking whether we are using GNU C... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for Cygwin environment... (cached) no
checking for mingw32 environment... (cached) no
checking for executable suffix... (cached) .dSYM
checking build system type... i386-apple-darwin10.2.0
checking for ranlib... (cached) ranlib
checking for ld used by GCC... (cached) /usr/libexec/gcc/i686-apple-darwin10/4.2.1/ld
checking if the linker (/usr/libexec/gcc/i686-apple-darwin10/4.2.1/ld) is GNU ld... (cached) no
checking for BSD-compatible nm... (cached) /usr/bin/nm
checking whether ln -s works... (cached) yes
loading cache ./config.cache within ltconfig
checking for object suffix... o
checking for executable suffix... (cached) .dSYM
checking for gcc option to produce PIC... -fPIC
checking if gcc PIC flag -fPIC works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.lo... yes
checking if gcc supports -fno-rtti -fno-exceptions ... no
checking if gcc static flag -static works... none
checking if the linker (/usr/libexec/gcc/i686-apple-darwin10/4.2.1/ld) is GNU ld... no
checking whether the linker (/usr/libexec/gcc/i686-apple-darwin10/4.2.1/ld) supports shared libraries... no
checking command to parse /usr/bin/nm output... rm: conftest.dSYM: is a directory
ok
checking how to hardcode library paths into programs... unsupported
checking for /usr/libexec/gcc/i686-apple-darwin10/4.2.1/ld option to reload object files... -r
checking dynamic linker characteristics... no
checking if libtool supports shared libraries... no
checking whether to build shared libraries... no
checking whether to build static libraries... yes
checking for objdir... .libs
creating libtool
loading cache ./config.cache
checking for working const... (cached) yes
checking for a BSD compatible install... /usr/bin/install -c
checking for ranlib... (cached) ranlib
checking whether ln -s works... (cached) yes
checking which tclConfig.sh to use... /usr/lib/tclConfig.sh
checking for your tcl version... 8.5, patchlevel .7
checking how to run the C preprocessor... (cached) gcc -E
checking for ANSI C header files... (cached) no
checking for string.h... (cached) yes
checking where to look for tcl.h... /usr/include/tcl.h
checking for tputs in -lncurses... (cached) yes
checking where to look for readline.h... /usr/local/include/readline/readline.h
checking for rl_callback_read_char in -lreadline... (cached) yes
checking for _rl_executing_macro in -lreadline... no
checking for rl_cleanup_after_signal() in -lreadline... yes
checking for the readline version number... failed
creating ./config.status
creating Makefile
creating tclreadline.h
creating tclreadlineInit.tcl
creating tclreadlineSetup.tcl
creating tclreadline.n
creating pkgIndex.tcl
creating config.h
config.h is unchanged
...ap/Downloads/tclreadline-2.1.0$ make
/bin/sh ./libtool --mode=compile gcc -DHAVE_CONFIG_H -I. -I. -I. -I/usr/include -I/usr/local/include/readline -g -O2 -c tclreadline.c
gcc -DHAVE_CONFIG_H -I. -I. -I. -I/usr/include -I/usr/local/include/readline -g -O2 -c tclreadline.c -o tclreadline.o
tclreadline.c: In function 'TclReadlineCmd':
tclreadline.c:225: warning: passing argument 3 of 'Tcl_GetIndexFromObj' from incompatible pointer type
tclreadline.c: In function 'TclReadlineCompletion':
tclreadline.c:748: warning: assignment makes pointer from integer without a cast
echo timestamp > tclreadline.lo
/bin/sh ./libtool --mode=link gcc -g -O2 -o libtclreadline.la -rpath /usr/lib -release 2.1.0 tclreadline.lo -lreadline -lncurses
rm -fr .libs/libtclreadline.la .libs/libtclreadline.* .libs/libtclreadline-2.1.0.*
ar cru .libs/libtclreadline.a tclreadline.o
ranlib .libs/libtclreadline.a
creating libtclreadline.la
(cd .libs && rm -f libtclreadline.la && ln -s ../libtclreadline.la libtclreadline.la)
...ap/Downloads/tclreadline-2.1.0$ sudo make install
Password:
/bin/sh ././aux/mkinstalldirs /usr/lib
/bin/sh ./libtool --mode=install /usr/bin/install -c libtclreadline.la /usr/lib/libtclreadline.la
/usr/bin/install -c .libs/libtclreadline.lai /usr/lib/libtclreadline.la
/usr/bin/install -c .libs/libtclreadline.a /usr/lib/libtclreadline.a
ranlib /usr/lib/libtclreadline.a
chmod 644 /usr/lib/libtclreadline.a
----------------------------------------------------------------------
Libraries have been installed in:
/usr/lib
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use `-LLIBDIR'
flag during linking and do at least one of the following:
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
/bin/sh ././aux/mkinstalldirs /usr/bin
/bin/sh ././aux/mkinstalldirs /usr/lib/tclreadline2.1.0
/usr/bin/install -c -m 644 pkgIndex.tcl /usr/lib/tclreadline2.1.0/pkgIndex.tcl
/usr/bin/install -c -m 644 tclreadlineCompleter.tcl /usr/lib/tclreadline2.1.0/tclreadlineCompleter.tcl
/usr/bin/install -c -m 644 tclreadlineInit.tcl /usr/lib/tclreadline2.1.0/tclreadlineInit.tcl
/usr/bin/install -c -m 644 tclreadlineSetup.tcl /usr/lib/tclreadline2.1.0/tclreadlineSetup.tcl
make install-mann
/bin/sh ././aux/mkinstalldirs /usr/man/mann
/usr/bin/install -c -m 644 ./tclreadline.n /usr/man/mann/tclreadline.n
/bin/sh ././aux/mkinstalldirs /usr/include
/usr/bin/install -c -m 644 tclreadline.h /usr/include/tclreadline.h


I don't see any mention of libtclreadline.dylib, and the rest is greek to me.

Is there a clue there?

Message was edited by: Chap Harrison - add URL to http://tclreadline.sourceforge.net/

Jan 20, 2010 7:22 AM in response to Chap Harrison

You have two issues.

One, that libreadline.dylib in /usr/lib is going to cause you some problems. Since you are installing a real readline, I say just move it aside. Use sudo to rename it "sudo mv /usr/lib/libreadline.dylib /usr/lib/oldlibreadline.dylib". It is only a symbolic link anyway.

Next, the tclreadline library uses old versions of autoconf. Before calling "./configure" on this project, run "autoreconf -fvi". That will enable shared libraries.

I am confident that this will work. If not, let me know and I will install all of tcl and the rest and see what happens. I would have already done that but these tools want to install into /usr/ instead of /usr/local and that's not cool.

Jan 20, 2010 3:17 PM in response to etresoft

Well, that certainly did get me a lot further along.

tclsh -i came up with an editable command line! Unfortunately, regardless of what I entered, tclsh croaked when I pressed return, as follows:

*/Users/chap$* tclsh -i
*tclsh8.5 [~]*puts "Hello, World"
alloc: invalid block: 0x10030b290: 7e 69
Abort trap

I found the solution at http://wiki.tcl.tk/5632:

+If you enable tclreadline in your tclsh and get an "alloc: invalid block: ..." error, then you will have to do the following:+
+Edit tclreadline.c file and rename all MALLOC to malloc and FREE to free (and remove the macros MALLOC and FREE)+

Haven't thoroughly tested but it seems to do the basic stuff.

I sure do appreciate your help and I'm marking this solved.

Chap

Adding readline support for tclsh

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.