I use LaTeX to write papers, and latexindent works very well on macOS Catalina.
But when I updated macOS to Big Sur, latexindent can't work anymore, prompting Can't locate File/HomeDir.pm in @INC.
So I used cpan
to install the module according to the prompt, and it says fatal error: 'EXTERN.h' file not found
.
I used stackoverflow to search the ways to figure it out, and I found this question is as same as mine.
So I find the directory which contains the header files perl needs on my Mac, and I set CPATH
. Then I type sudo cpan
to open the cpan shell, and type install Mac::SystemDirectory
. and the prompt is as follows:
Reading '/Users/myname/.cpan/Metadata'
Database was generated on Thu, 18 Mar 2021 01:56:22 GMT
Running install for module 'Mac::SystemDirectory'
Checksum for /Users/myname/.cpan/sources/authors/id/E/ET/ETHER/Mac-SystemDirectory-0.13.tar.gz ok
Scanning cache /Users/myname/.cpan/build for sizes
............................................................................DONE
'YAML' not installed, will not store persistent state
Configuring E/ET/ETHER/Mac-SystemDirectory-0.13.tar.gz with Makefile.PL
HASCOMPILERdZv0/TESTgu8P.c:2:10: fatal error: 'EXTERN.h' file not found
#include "EXTERN.h"
^~~~~~~~~~
1 error generated.
Couldn't execute cc -g -pipe -fno-strict-aliasing -fstack-protector-strong -DPERL_USE_SAFE_PUTENV -Os "-I/System/Library/Perl/5.28/darwin-thread-multi-2level/CORE" -c HASCOMPILERdZv0/TESTgu8P.c -o HASCOMPILERdZv0/TESTgu8P.o: Inappropriate ioctl for device at Makefile.PL line 14.
Requires a compiler
Warning: No success on command[/usr/bin/perl Makefile.PL]
ETHER/Mac-SystemDirectory-0.13.tar.gz
/usr/bin/perl Makefile.PL -- NOT OK
Failed during this command:
ETHER/Mac-SystemDirectory-0.13.tar.gz : writemakefile NO '/usr/bin/perl Makefile.PL' returned status 6400
It seems CPATH not working. I also tried to copy all the header files in the CORE directory corresponding to CPATH
to the /System/Library/Perl/5.28/darwin-thread-multi-2level/CORE
directory, but even if I used the sudo
command, it still failed, I don't know why.
So although I set $CPATH
, judging from the above error output, the compiler did not use the $CPATH
environment variable but still went to the /System/Library/Perl/5.28/darwin-thread-multi-2level/CORE
directory to look for the header file.
I want to know why this is and how to solve this problem.
PS: I know somebody set CPATH to solve the question, but it did not work for me.
~/.cpan
's owner is root
instead of me.
The first time I use cpan
to install some modules(without root
), it said You do not have write permission for Perl library directories.
, and it asked me which approach I want, I chose local::lib
,and I can successfully install Mac::SystemDirectory
But later when I installed File::HomeDir
, it said
ERROR: Can't create '/Library/Perl/5.28/darwin-thread-multi-2level/Mac'
mkdir /Library/Perl/5.28/darwin-thread-multi-2level/Mac: Permission denied at /System/Library/Perl/5.28/ExtUtils/Install.pm line 489.
So I just remove ~/.cpan
and I choose root
now.
Solution: I just delete directory ~/perl5
and ~/.cpan
, reboot my Mac. And I type cpan install <some_module>
(without root), cpan asked me to choose the approach I want, this time I chose sudo
and type my root password, and It worked! BTW, if used sudo
to run some command, it means let the superuser root
run this command, and root's environment variable is not same as yours, that is the reason why I set the CPATH
and run sudo cpan ...
but not working!