Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Successfully loading an uninstalled library from a Makefile test?

24 views
Skip to first unread message

Nate Bargmann

unread,
Jul 26, 2017, 1:48:58 PM7/26/17
to
My apologies if this is an FAQ.

I am going through parts of a library project that I help maintain and
would like to be able to run a short test TCL script using the uninstalled
library generated by SWIG and GNU Libtool. I will admit to being rather
unfamiliar with the intricacies of TCL's loading mechanism.

The following target is written into the local Makefile.am:

check-tcl: all-tcl
TCLLIBPATH=$(builddir)/.libs tclsh $(builddir)/tcltest.tcl \
|| echo "Tcl test failed" 1>&2

Libtool puts the newly compiled library in the .libs directory below the
directory the generated tcltest.tcl script is placed in the build tree.

Near the top of the 'tcltest.tcl' script is the following line:

lappend ::auto_path /usr/local/lib/tcl8.6/Hamlib

The path is written to the script file by the Makefile through a variable
substitution to reflect the directory the library will be installed to.
Once the main library and the generated TCL library are installed, the
'check-tcl' target succeeds.

After uninstalling the library and the generated TCL library and trying to
run the test results in:

$ make check-tcl
TCLLIBPATH=./.libs tclsh ./tcltest.tcl \
|| echo "Tcl test failed" 1>&2
can't find package hamlib
while executing
"package require hamlib"
(file "./tcltest.tcl" line 12)
Tcl test failed


It seems to me that even setting TCLLIBPATH has no effect.

What am I missing?

TIA

- Nate

--

"The optimist proclaims that we live in the best of all
possible worlds. The pessimist fears this is true."

Ham radio, Linux, bikes, and more: http://www.n0nb.us

Mike Griffiths

unread,
Jul 26, 2017, 4:47:20 PM7/26/17
to
[package require] checks the directories in $auto_path for pkgIndex.tcl files, and sources those; each one uses one or more [package ifneeded] commands to tell Tcl about the packages that are available. So, if you don't have one already, you'll need to add a pkgIndex.tcl file in /usr/local/lib/tcl8.6/Hamlib which contains a line along the lines of:

package ifneeded hamlib 1.0 "[list load [file join $dir hamlib.[info sharedlibextension]]];package provide hamlib 1.0"

$dir is automatically set to the directory the pkgIndex.tcl file is in, and should be used for building paths to files that need to be loaded/sourced.

It seems there's a tool for generating the necessary package ifneeded line - http://www.tcl.tk/man/tcl/TclCmd/packagens.htm - though it doesn't do the [package provide], which is essential, so you must either add that manually to the [package ifneeded], or make sure your library does it already (either through the Tcl C API or in a sourced Tcl file.

Nate Bargmann

unread,
Jul 27, 2017, 3:42:49 PM7/27/17
to
Thanks for the follow up, Mike.

On Wed, 26 Jul 2017 13:47:16 -0700, Mike Griffiths wrote:

> [package require] checks the directories in $auto_path for pkgIndex.tcl
> files, and sources those;

This was the key I apparently needed. I manually copied the generated
pkgIndex.tcl into the .libs directory and the script ran successfully. I
have now coded that step into the Makefile.am, tested, and can continue on.

Thanks!

Mike Griffiths

unread,
Jul 27, 2017, 4:40:35 PM7/27/17
to
My pleasure :)
0 new messages