Linking to correct Tcl/Tk frameworks on macOS

[email protected] (Kevin Walzer) Sun, 29 Nov 2020 20:06:36 -0500
Newsgroups perl.tcltk
Message-ID <CAPQgQk4dQFyigug9An-iXavsY7weG17hw_56vtSWFt7m9O76eA@mail.gmail.com>
--000000000000d3a22505b5489f41
Content-Type: text/plain; charset="UTF-8"

Hello all,

I've seen a few email queries on this list (cf.
https://www.nntp.perl.org/group/perl.tcltk/2018/08/msg770.html ) about how
to link to specific versions of the Tcl/Tk frameworks on macOs if you are
using one of the Perl libraries that interface to these frameworks (tkx,
tcl::tk, etc.), and especially if you are deploying a standalone app
bundle.

What has worked for me is to set specific environmental flags at the start
of my main Perl script in my app bundle, which I am currently using in
FileMorph (https://www.codebykevin.com/filemorph.html). Here is the code
snippet I use:

use FindBin qw($Bin);
use File::Basename;
use Config;

BEGIN {
    if ( $Config{osname} eq "darwin" && $ENV{PAR_TEMP} ) {
        my $frameworkpath =
          dirname($Bin) . "/Frameworks/Tcl.framework/Versions/8.6/Tcl";
        $ENV{'PERL_TCL_DL_PATH'} = $frameworkpath;
        $helpdir = dirname($Bin) . '/Resources/FileMorph\\ User\\
Help.help';
    }
    if ( $Config{osname} eq "MSWin32" ) {
        my $frameworkpath = "$Bin/Tcl86/bin/tcl86t.dll";
        $ENV{'PERL_TCL_DL_PATH'} = $frameworkpath;
    }
}

This code has a couple of extra references to PAR/pp environmental
variables, but essentially, on the Mac I use FindBin to locate the
installation of my application, map the Tcl framework within that
installation, and then set that as the library path for Tcl/Tk for Perl to
interface with.

I hope this is helpful to others.

--Kevin

--000000000000d3a22505b5489f41
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div di=
r=3D"ltr">Hello all,<div><br></div><div>I&#39;ve seen a few email queries o=
n this list (cf.=C2=A0<a href=3D"https://www.nntp.perl.org/group/perl.tcltk=
/2018/08/msg770.html">https://www.nntp.perl.org/group/perl.tcltk/2018/08/ms=
g770.html</a> ) about how to link to specific versions of the Tcl/Tk framew=
orks on macOs if you are using one of the Perl libraries that interface to =
these frameworks (tkx, tcl::tk, etc.), and especially if you are deploying =
a standalone app bundle.=C2=A0</div><div><br></div><div>What has worked for=
 me is to set specific=C2=A0environmental flags at the start of my main Per=
l script in my app bundle, which I am currently using in FileMorph (<a href=
=3D"https://www.codebykevin.com/filemorph.html">https://www.codebykevin.com=
/filemorph.html</a>). Here is the code snippet I use:=C2=A0</div><div><br><=
/div><div><div>use FindBin qw($Bin);</div><div>use File::Basename;</div><di=
v>use Config;</div></div><div><br></div><div><div>BEGIN {</div><div>=C2=A0 =
=C2=A0 if ( $Config{osname} eq &quot;darwin&quot; &amp;&amp; $ENV{PAR_TEMP}=
 ) {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 my $frameworkpath =3D</div><div>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 dirname($Bin) . &quot;/Frameworks/Tcl.fr=
amework/Versions/8.6/Tcl&quot;;</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 $ENV{=
&#39;PERL_TCL_DL_PATH&#39;} =3D $frameworkpath;</div><div>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 $helpdir =3D dirname($Bin) . &#39;/Resources/FileMorph\\ User\\ =
Help.help&#39;;</div><div>=C2=A0 =C2=A0 }</div><div>=C2=A0 =C2=A0 if ( $Con=
fig{osname} eq &quot;MSWin32&quot; ) {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 my $frameworkpath =3D &quot;$Bin/Tcl86/bin/tcl86t.dll&quot;;</div><div>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 $ENV{&#39;PERL_TCL_DL_PATH&#39;} =3D $framework=
path;</div><div>=C2=A0 =C2=A0 }</div><div>}</div></div><div><br></div><div>=
This code has a couple of extra references to PAR/pp environmental variable=
s, but essentially, on the Mac I use FindBin to locate the installation of =
my application, map the Tcl framework within that installation, and then se=
t that as the library path for Tcl/Tk for Perl to interface with.=C2=A0</di=
v><div><br></div><div>I hope this is helpful to others.=C2=A0</div><div><br=
></div><div>--Kevin=C2=A0</div></div></div></div></div></div>

--000000000000d3a22505b5489f41--