gisle / tcl.pm

Tcl extension module for Perl
http://search.cpan.org/dist/Tcl
9 stars 8 forks source link

Error installing on macOS (Monterey) #43

Closed fantinuoli closed 6 months ago

fantinuoli commented 2 years ago

I can not install Tcl using the following:

Perl (v5.34.1) installed with perlbrew Tcl-Tk installed with brew (brew install tcl-tk) In Terminal added:

  export LDFLAGS="-L/usr/local/opt/tcl-tk/lib"
  export CPPFLAGS="-I/usr/local/opt/tcl-tk/include"

Then

cpan Tcl

What I get is

166 warnings and 2 errors generated.
make: *** [Tcl.o] Error 1
  VKON/Tcl-1.27.tar.gz
  /usr/bin/make -- NOT OK

The error I see in the log is

/Library/Developer/CommandLineTools/SDKs/MacOSX12.0.sdk/usr/include/mach/mach.h:86:33: error: redefinition of 'tclStubsPtr' as different kind of symbol
extern void                     panic(const char *, ...);

If I try to generate the Makefile.pl what I see is:

tclsh=/usr/bin/tclsh
tcl_library=/System/Library/Frameworks/Tcl.framework/Versions/8.5/Resources/Scripts
tcl_version=8.5
LIBS   = -Ltcl-core/darwin-universal -ltclstub8.4 -framework Carbon
INC    = -Itcl-core/include
DEFINE =  -DUSE_TCL_STUBS -DTCLSH_PATH=\"/usr/bin\"
tclConfig.sh = 
Generating a Unix-style Makefile
Writing Makefile for Tcl
Writing MYMETA.yml and MYMETA.json

So, I GUESS, it has something to do with Tcl not seeing any Tcl/Tk installation. Any suggestion?

vadrer commented 2 years ago

that output means that tcl/tk is found. should work. The C compiler error needs to be investigated. Can you track why the redifinition of tclStubsPtr happens in your case? what is $^O in your system? is it 'darwin'?

chrstphrchvz commented 2 years ago

Based on the Tcl version detected being 8.5, I think the Tcl included with macOS is being found instead of Homebrew Tcl (version 8.6). Makefile.PL probably needs more information to find Homebrew (using cpanm --configure-args=… may help here).

If your use case allows, I would also specify --nousestubs to Makefile.PL to avoid the tclStubsPtr redefinition issue.

chrstphrchvz commented 2 years ago

Here is how I would explain the tclStubsPtr redefinition issue:

Tcl.xs first includes tcl.h, which

  1. defines panic as Tcl_Panic and
  2. includes tclDecls.h which defines Tcl_Panic as tclStubsPtr->tcl_Panic

But Tcl.xs later includes <CoreServices/CoreServices.h>, and as of the macOS 11 SDK, this header now indirectly includes the system header <mach/mach.h> which declares panic().

Tcl.pm presumably should patch or update its tcl.h. Tcl has known about the conflict with <mach/mach.h> at least since 2016, and resolved it in tcl.h in 8.6.7 (https://github.com/tcltk/tcl/commit/99fd1215e29a440df99afb1b967c6e91faffa7c6):

#if !defined(__APPLE__) /* On OSX, there is a conflict with "mach/mach.h" */
#   define panic        Tcl_Panic
#endif

Note that the panic() definition in tcl.h was only for compatibility with older extensions; anything still using it (e.g. TkTable) should just be migrated to Tcl_Panic().

chrstphrchvz commented 2 years ago

And for reasons described in https://rt.cpan.org/Ticket/Display.html?id=132729 and https://rt.cpan.org/Ticket/Display.html?id=132668, Tcl.pm built with stubs is broken on macOS.

fantinuoli commented 2 years ago

I manage to install Tcl by

export LDFLAGS="-L/usr/local/opt/tcl-tk/lib"
export CPPFLAGS="-I/usr/local/opt/tcl-tk/include"
export PKG_CONFIG_PATH="/usr/local/opt/tcl-tk/lib/pkgconfig"
cpan Tcl

Which produced this configuration

Running install for module 'Tcl'
Checksum for /Users/fc/.cpan/sources/authors/id/V/VK/VKON/Tcl-1.27.tar.gz ok
'YAML' not installed, will not store persistent state
Configuring V/VK/VKON/Tcl-1.27.tar.gz with Makefile.PL
tclsh=/usr/local/opt/tcl-tk/bin/tclsh
tclConfig.sh=/usr/local/Cellar/tcl-tk/8.6.12_1/lib/tclConfig.sh
tcl_library=/usr/local/Cellar/tcl-tk/8.6.12_1/lib/tcl8.6
tcl_version=8.6
Using config data in /usr/local/Cellar/tcl-tk/8.6.12_1/lib/tclConfig.sh
LIBS   = -L/usr/local/Cellar/tcl-tk/8.6.12_1/lib -ltclstub8.6
INC    = -I/usr/local/Cellar/tcl-tk/8.6.12_1/include
DEFINE =  -DUSE_TCL_STUBS -DTCLSH_PATH=\"/usr/local/opt/tcl-tk/bin\" -DLIB_RUNTIME_DIR=\"/usr/local/Cellar/tcl-tk/8.6.12_1/lib\" -DTCL_LIB_FILE=\"libtcl8.6.dylib\"
tclConfig.sh = /usr/local/Cellar/tcl-tk/8.6.12_1/lib/tclConfig.sh
Checking if your kit is complete...
Looks good

This produced a very high number of warnings I have never seen before while installing Tcl. Not sure how preoccupying these warnings are.

Subsequent installation of Tcl::pTk was possible only with -force .

Files=132, Tests=467, 250 wallclock secs ( 0.48 usr  0.40 sys + 30.11 cusr 11.01 csys = 42.00 CPU)
Result: FAIL
Failed 6/132 test programs. 7/467 subtests failed.
make: *** [test_dynamic] Error 255

But I will run some other experiments and eventually open a ticket in Tcl::pTk, if the problem persist.

chrstphrchvz commented 2 years ago

This produced a very high number of warnings I have never seen before while installing Tcl. Not sure how preoccupying these warnings are.

I believe you are referring to the -Wcompound-token-split-by-macro warnings emitted by newer clang, which is affecting many XS modules and may be up to Perl core to address in a future release, see e.g. http://blogs.perl.org/users/tom_wyant/2022/03/xs-versus-clang-infinite-warnings.html

fantinuoli commented 2 years ago

Thank you for following up. Yes, this is the repeating warning.

My installation seems okay. Both Tcl and Tcl:pTk work like expected both on my Intel and M1 machines.

PS: I do not know all the intricacies of Tcl, but it would be nice if the module could be installed even without any Tcl/Tk installation in place. In many cases, users may be interested to point to specific Tcl/Tk binaries at runtime.

chrstphrchvz commented 2 years ago

Subsequent installation of Tcl::pTk was possible only with -force … But I will run some other experiments and eventually open a ticket in Tcl::pTk, if the problem persist.

I would encourage you to open an issue for Tcl::pTk, providing the “Test Summary Report” may be enough. I am looking into some recent test failures for Tcl::pTk on macOS Aqua; some of these appear to be caused by upstream Tk Aqua issues.

PS: I do not know all the intricacies of Tcl, but it would be nice if the module could be installed even without any Tcl/Tk installation in place.

Normally Tcl.pm’s Makefile.PL wants access to tclsh to retrieve Tcl installation info even when building to use stubs, but if this fails it falls back to using a stubs library and include directory within the Tcl.pm distribution. It seems possible to build Tcl.pm with stubs support and without access to a Tcl installation by manually specifying these fallback options directly to Makefile.PL:

perl5.34 Makefile.PL --library='-Ltcl-core/darwin-universal -ltclstub8.4' --include='-Itcl-core/include'

Although maybe there is already a better way to do this, and/or improvements are possible to Makefile.PL to make this easier.

In many cases, users may be interested to point to specific Tcl/Tk binaries at runtime.

If Tcl.pm is built to use stubs, then the specific Tcl installation used at runtime can be controlled by setting the undocumented $Tcl::DL_PATH variable, which can also be set using environment variables (https://www.nntp.perl.org/group/perl.tcltk/2020/11/msg843.html mentions PERL_TCL_DL_PATH).