Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

macOS tcl::pTk packing Tcl

by IB2017 (Pilgrim)
on May 29, 2018 at 11:28 UTC ( #1215353=perlquestion: print w/replies, xml ) Need Help??

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

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.

Replies are listed 'Best First'.
Re: macOS tcl::pTk packing Tcl
by Anonymous Monk on May 29, 2018 at 17:20 UTC
    Are you saying PERL_TCL_DL_PATH is disregarded?

      No, I am saying that I am not able to make it work, actually I do not know if it is disregared or not (maybe it is just me that is unable to put the right path). To be more explicitly, what do I have to set in the next BEGIN for $frameworkpath if I want to use, let's say, the default Tcl which the program above says is - as far as Tk is concerned - in /System/Library/Frameworks/Tk.Framework/Versions/8.5/Resources (I want to 'override' the environment path now, as an exercise, but for true I want to link it to a Tcl installation which is in another path.)

      BEGIN { my $frameworkpath = ""; print $ENV{'PERL_TCL_DL_PATH'} = $frameworkpath; }

      Something like this does not work: my $frameworkpath = "/Library/Frameworks/Tcl.Framework/Versions/8.5/Resources/"; (I just installed ActiveTcl, this gets linked to my script, but I want to resort to the default Tcl installed in my Mac)

        Why don't you know? Don't you get a warning when it fails to load the dll you specify?

        Also did you just switch what you wanted? That (I just installed ActiveTcl, this gets linked to my script, but I want to resort to the default Tcl installed in my Mac)

Re: macOS tcl::pTk packing Tcl
by chrstphrchvz (Scribe) on Jul 20, 2018 at 02:54 UTC

    Tcl::pTk is pure Perl, so by itself it doesn't know about where to look for Tcl/Tk. However the Tcl.pm module it uses should be able to be told where to find Tcl/Tk. I'm not very knowledgeable about this, so I would try asking the folks at tcltk@perl.org who know more about Tcl.pm.

      There's currently a very brief explanation of choices at https://metacpan.org/pod/Tcl#Moving-Tcl/Tk-around-with-Tcl.pm. The second method (install Tcl/Tk to a known location, then tell Tcl.pm to use only that Tcl/Tk installation) or third method (static linking of Tcl.pm to Tcl/Tk, on-demand extracting of Tcl/Tk files) are what sound appropriate for this scenario.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1215353]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (1)
As of 2022-11-26 15:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?