Takamoto has asked for the wisdom of the Perl Monks concerning the following question:

See UPDATE below:

I've been fighting for the last two days trying to link the (already installed) Tcl.pm module to another Tcl.dll . This is my machine:

Now, no Tcl/Tk is in the permanent Windows Path (and I do not want to have it), no other Tcl/Tk installation is on my machine, only the one above in C:/. I want Tcl.pm to link to this installation, independently to the Tcl installation Tcl.pm was linked to (visible) at the moment of installation. Plus, I do not want to modify permanently my Path. After reading posts everywhere, I was sure the following would work:

use strict; use warnings; BEGIN { print "Starting script on MSWIN\n"; my $pathTCL = "C:/Tcl/bin/tcl86.dll"; print "TCL: " . $pathTCL . "\n"; $ENV{'PERL_TCL_DL_PATH'} = $pathTCL;# showld be the same of: PERL_ +TCL_DLL } use Tcl;

Unfortunately, I get the following, which for me is quite strange...

Starting script on MSWIN TCL: C:/Tcl/bin/tcl86.dll NpLoadLibrary: could not find Tcl library at 'C:/Tcl/bin/tcl86.dll' at + C:/Strawberry/perl/lib/XSLoader.pm line 111. Failed to load Tcl dll! at C:/Strawberry/perl/lib/XSLoader.pm line 111 +. Unable to initialize Tcl at C:/Strawberry/perl/lib/XSLoader.pm line 11 +1. Compilation failed in require at .\wheel.pl line 11. BEGIN failed--compilation aborted at .\wheel.pl line 11.

UPDATE

This is a working solution, but I would like to hear from you if my approach is right. Adding the Tcl bin to $ENV{PATH} seems to make the Tcl installation visible to Tcl.pm. However, I am not a MS Windows man and I am not accustomed to manipulating $ENV in MS Windows, especially within a BEGIN. So, I am wondering if my hack will give me bad surprises (for example Perl is no more in $ENV after the Begin block). Any comment will be very much appreciated.

use warnings; use FindBin qw($Bin); BEGIN { print "Starting script on MSWIN \n"; print "My directory: $Bin\n"; my $pathTclDLL = $Bin . "\\tcltk2\\bin\\tcl86.dll"; my $pathTclBin = $Bin . "\\tcltk2\\bin"; print "TCL DLL: " . $pathTclDLL . "\n"; print "TCL BIN: " . $pathTclBin . "\n"; $ENV{PATH}=$pathTclBin; $ENV{'PERL_TCL_DL_PATH'} = $pathTclDLL; print "Printing ENV\n"; print my $path = $ENV{'PATH'}; } use Tcl;

Replies are listed 'Best First'.
Re: Link Tcl to a different tcl.dll on Windows
by syphilis (Bishop) on Jan 25, 2020 at 01:21 UTC
    $ENV{'PERL_TCL_DL_PATH'} = $pathTclDLL;

    That line (from the "update" section of your post) looks dubious to me.
    It sets:
    $ENV{'PERL_TCL_DL_PATH'} = $Bin . "\\tcltk2\\bin\\tcl86.dll"; but you probably want $ENV{'PERL_TCL_DL_PATH'} = $Bin . "\\tcltk2\\bin";
    I suspect that the updated script works because $ENV{PATH} provides everything that's needed, and that you could remove all lines that mention $pathTclDLL - and the script would still work.

    Cheers,
    Rob

      You are right, Rob. It works. However, now No, this does not solves the issue. I am more confused than before. In any post I have seen (mainly dealing with Tkx which should rely on Tcl.pm) I have always seen $ENV{'PERL_TCL_DL_PATH'} used with dll.

      For now, it works only with the script I proposed above.

        That feature is for packagers like PAR/pp. Not for mixing incompatible bin/tcl
Re: Link Tcl to a different tcl.dll on Windows
by jcb (Curate) on Jan 25, 2020 at 00:42 UTC

    Yes, your solution probably removes perl from %PATH% after the BEGIN block. I can think of two reasonable answers at the moment: (both untested)

    1. Move use Tcl; into the BEGIN block and use local when adjusting $ENV{PATH}.
    2. Prepend the Tcl directory to the PATH with $ENV{PATH} = $pathTclBin . ';' . $ENV{PATH}; instead of replacing PATH. (The PATH separator is colon on POSIX and semicolon on Windows.)

      Thank you, jcb. I think prepending the Tcl directory seems to me the best option at the moment!

Re: Link Tcl to a different tcl.dll on Windows
by Anonymous Monk on Jan 24, 2020 at 21:29 UTC

    When/How did you install Tcl.pm?

Re: Link Tcl to a different tcl.dll on Windows
by Anonymous Monk on Jan 24, 2020 at 22:30 UTC

    I've been fighting for the last two days trying to link the (already installed) Tcl.pm module to another Tcl.dll .

    You should reinstall Tcl.pm so it knows about the new dll when you're running  perl Makefile.PL

      I do not want to reinstall Tcl.pm. This of course would work fine. What I want is the ability to link, possibly at runtime, to a Tcl installation of my choice which is present on my computer. And this independently of the Tcl installation I pointed Tcl.pm to at the moment of its installation. See my update for the best solution I managed to get so far.

        I do not want to reinstall Tcl.pm. This of course would work fine. What I want is the ability to link, possibly at runtime, to a Tcl installation of my choice which is present on my computer. And this independently of the Tcl installation I pointed Tcl.pm to at the moment of its installation. See my update for the best solution I managed to get so far.

        The simplest way to ensure the two are compatible is to test/build from start -- figure out what works when its supposed to work 100%