3

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!

chenlangping
  • 101
  • 2
  • 7
  • *"sudo cpan"* Did you set CPATH for root user or for your regular user? – Håkon Hægland Mar 18 '21 at 07:19
  • If I don't use "sudo", then `Couldn't mkdir '/Users/myname/.cpan/build/tmp-70881': Permission denied` – chenlangping Mar 18 '21 at 08:14
  • *"Couldn't mkdir ..."* : This happens if you run `cpan Mac::SystemDirectory` (note: not sudo in front of cpan) from the shell prompt? – Håkon Hægland Mar 18 '21 at 08:17
  • Yes, If I add `sudo` before `cpan install Mac::SystemDirectory` ,then I will get `fatal error: 'EXTERN.h' file not found` – chenlangping Mar 18 '21 at 08:24
  • Seems like somehow your `.cpan` directory has gotten the wrong access permissions ? What is the output of `ls -ld ~/.cpan` ? (It should be owned by you and not root user) – Håkon Hægland Mar 18 '21 at 08:52
  • You can also run the command `stat -f '%Su' ~/.cpan` to get the user ID of the directory – Håkon Hægland Mar 18 '21 at 09:03
  • Re "*If I don't use "sudo",*" HH didn't say don't use `sudo`; they suggesting forcing sudo to inherit the `CPATH` or setting `CPATH` *after* using `sudo`. e.g. `sudo bash -l`, then `export CPATH=...`, then `cpan ...` – ikegami Mar 18 '21 at 12:07
  • *"So I just remove ~/.cpan and I choose root now."* Were you able to set `CPATH` for root user also? – Håkon Hægland Mar 19 '21 at 07:53
  • 2
    I just delete `~/perl5` and `~/.cpan`, reboot my MAC and I type `cpan install ..`, then I chose `sudo` instead of `local::lib`. `cpan` asked me to input my password , and it worked this time! Thanks a lot! @Håkon @ikegami – chenlangping Mar 19 '21 at 10:59

0 Answers0