I am experimenting with Tcl::pTk after being inspired by some recent posts on this group. I need to create an executable for macOS of my Tcl::pTk application with pp and bundle it in a .app for distribution. Let’s say it is a simple GUI that reads the tcl version:
use strict;
use warnings;
use Tk;
use Tcl::pTk;
my $int = new Tcl::pTk;
$int->Eval(<<'EOS');
# pure-tcl code to create widgets (e.g. generated by some GUI builder)
text .e
## http://wiki.tcl.tk/1626#tk_version
.e insert end "tcl_version $tcl_version\n"
.e insert end "tcl_patchLevel $tcl_patchLevel\n"
.e insert end "tk_version $tk_version\n"
.e insert end "tk_patchLevel $tk_patchLevel\n"
.e insert end "tk_library $tk_library\n"
pack .e
EOS
my $e = $int->widget('.e'); # get .e entry into play
$e->insert( "end", "
Tcl::pTk $Tcl::pTk::VERSION
Tcl $Tcl::VERSION
\$^V $^V
\$] $]
");
$int->MainLoop;
The executable is generated with:
pp -o TEST test.pl
The generated executable works fine and uses the Tcl version that it finds on the system (normally the standard tcl framework in HD/System/Library/Frameworks/Tk.framework (8.5)). If I install a new Tcl version (for example ActiveTcl 8.6) or if I run it on another machine, the executable will automatically link to the new tcl framework. If I understand it correctly, the Tcl/Tcl::pTk modules dynamically read the directory where to find Tcl (using some environmental variables?). With this architecture, however, I am not in control over the Tcl version my application will use on a third machine. Not nice. The better option would be to include a tcl framework in my .app. I need to ship it within the .app containing my executable and have tcl/tcl::pTk inside my executable linked to it. A normal .app has the following structure:
MyApp.app/
Contents/
Info.plist
Frameworks/
Tcl.framework/
Tk.framework/
MacOS/
TEST
Resources/
MyApp.icns
How do I link my Tcl/Tcl::pTk modules (packed in TEST) to this particular installation of Tcl? I guess I should change the environmental path at the beginning of my script. Some posts here on perlmonks (related to Windows however) say it is necessary to set PERL_TCL_DL_PATH in a begin loop, but after two days of trying I haven't come up with any working solution. Any suggestion would be VERY MUCH appreciated.