ld: file not found: /usr/lib/crt1.o

Viewed 3291

When trying to compile Fortran using PGI on Mac OS X Sierra, I get the error

ld: file not found: /usr/lib/crt1.o

I found a workaround for older Mac OS X versions (http://www.pgroup.com/userforum/viewtopic.php?t=4578)

sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib/crt1.o /usr/lib/crt1.o 

However, with Sierra, System Integrity Protection prevents writing in /usr/bin. How can I solve this problem?

I tried linking into /usr/local/bin/ (which is permitted), but then, how can I make sure the compiler searches for library in that path?

4 Answers

Solution for command line programs:

The correct answer for me was as explained in this link:

https://medium.com/@kviat/free-pascal-3-0-2-linking-on-macos-sierra-c40706e86fda

After some googling I realized that most libraries were removed from /usr/lib in macOS Sierra. However this case is handled in FPC, so we just need to set internal compiler variable MacOSXVersionMin to 10.8 (or later). There is no standard compiler option for it, but after some search in source code I found the solution: set the environment variable MACOSX_DEPLOYMENT_TARGET:

You should give the deployment target of MacOS:

MACOSX_DEPLOYMENT_TARGET= XX.XX #for instance 10.15

Solution for generally:

Linking the necessary file to /usr/bin/crt* . As already stated, this linking will be prohibited by MacOs beginning from 10.10. But there is still a way to accomplish this linking procedure and it solves the problem.

1) Reboot the Mac and hold down Command + R keys simultaneously after you hear the startup chime, this will boot Mac OS X into Recovery Mode

2) When the “MacOS Utilities” / “OS X Utilities” screen appears, pull down the ‘Utilities’ menu at the top of the screen instead, and choose “Terminal

3) Type the following command into the terminal then hit return:

csrutil disable; reboot

4) When you come back, run the command sudo mount -uw /

5) Just run the linking code you want to:

sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib/crt1.o /usr/lib/crt1.o

sources: http://osxdaily.com/2015/10/05/disable-rootless-system-integrity-protection-mac-os-x/ https://www.reddit.com/r/MacOS/comments/caiue5/macos_catalina_readonly_file_system_with_sip/

In my case the problem was actually an error on the PGI installation side. PGI seems to be well aware that newer versions of macOS do not have the /usr/lib/crt1.o and that you can't create files there anymore. But it is possible to setup correct environment variables for the PGI compilers and then the linker should use the correct path to the crt1.o.

This configuration should be done automatically during the installation of the PGI compiler suite by running the makelocalrc command and should generate the file /opt/pgi/osx86-64/$PGIVER/bin/localrc. But in my case this step failed silently.

Reasons for failure seem to be:

  • license agreement for XCode not (yet) accepted, although this error should leave you with a /opt/pgi/osx86-64/$PGIVER/bin/localrc.error, containing some details
  • XCode version not supported, which seems to leave you with nothing. This is what I got when I ran the makelocalrc script manually:
makelocalrc -x /opt/pgi/osx86-64/19.10
 Error: Unsupported XCode version  11

In my case (PGI 19.10, macOS 10.15, XCode 11.2.1) I manually patched the /opt/pgi/osx86-64/19.10/bin/makelocalrc to not error out on XCode 11:

if test $xcodever -gt 11 ; then  # <-- was "-gt 10"!
     echo " Error: Unsupported XCode version "  $xcodever
     exit  -1
fi

and then re-ran the script after which compilation with PGI compilers (both pgcc and pgfortran) worked:

sudo /opt/pgi/osx86-64/2019/bin/makelocalrc -x /opt/pgi/osx86-64/19.10

Your case may vary, but you might want to check for a /opt/pgi/osx86-64/$PGIVER/bin/localrc.error or the /opt/pgi/osx86-64/$PGIVER/bin/localrc itself and try to manually (re-) generate it if it is not there or if you upgraded XCode/macOS since the installation of the PGI compilers.

Related