Can't compile C program on a Mac after upgrade to Mojave

前端 未结 15 672
陌清茗
陌清茗 2020-11-22 06:58

I have used the gcc command on the terminal to compile C programs but all of a sudden, after an update to my Mac\'s OS (to macOS 10.14 Mojave, and XCode 10.0), I started rec

相关标签:
15条回答
  • 2020-11-22 07:36

    After trying every answer I could find here and online, I was still getting errors for some missing headers. When trying to compile pyRFR, I was getting errors about stdexcept not being found, which apparently was not installed in /usr/include with the other headers. However, I found where it was hiding in Mojave and added this to the end of my ~/.bash_profile file:

    export CPATH=/Library/Developer/CommandLineTools/usr/include/c++/v1

    Having done that, I can now compile pyRFR and other C/C++ programs. According to echo | gcc -E -Wp,-v -, gcc was looking in the old location for these headers (without the /c++/v1), but not the new location, so adding that to CFLAGS fixed it.

    0 讨论(0)
  • 2020-11-22 07:36

    @JL Peyret is right!

    if you macos 10.14.6 Mojave, Xcode 11.0+

    then

    cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs

    sudo ln -s MacOSX.sdk/ MacOSX10.14.sdk

    0 讨论(0)
  • 2020-11-22 07:37

    I was having this issue and nothing worked. I ran xcode-select --install and also installed /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg.

    BACKGROUND

    Since I was having issues with App Store on a new laptop, I was forced to download the Xcode Beta installer from the Apple website to install Xcode outside App Store. So I only had Xcode Beta installed.

    SOLUTION

    This, (I think), was making clang to not find the SDKROOT directory /Applications/Xcode.app/...., because there is no Beta in the path, or maybe Xcode Beta simply doesn't install it (I don't know). To fix the issue, I had to remove Xcode Beta and resolve the App Store issue to install the release version.

    tldr;

    If you have Xcode Beta, try cleaning up everything and installing the release version before trying out the solutions that are working for other people.

    0 讨论(0)
  • 2020-11-22 07:42

    The problem is that Xcode, especially Xcode 10.x, has not installed everything, so ensure the command line tools are installed, type this in a terminal shell:

    xcode-select --install

    also start Xcode and ensure all the required installation is installed ( you should get prompted if it is not.) and since Xcode 10 does not install the full Mac OS SDK, run the installer at

    /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

    as this package is not installed by Xcode 10.

    0 讨论(0)
  • 2020-11-22 07:43

    I've found great solution and explanation at this GitHub comment. The trick:

    make SDKROOT=`xcrun --show-sdk-path` MACOSX_DEPLOYMENT_TARGET=
    

    Did the job.

    0 讨论(0)
  • 2020-11-22 07:45

    When you

    • updated to Mojave 10.14.6
    • your /usr/include was deleted again
    • the package mentioned in @Jonathan-lefflers answer doesn't exist anymore The file /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg does not exist. and
    • Xcode complains that command line tools are already installed xcode-select --install xcode-select: error: command line tools are already installed, use "Software Update" to install updates

    Then, what helped me recover the mentioned package, was deleting the whole CommandLineTools folder (sudo) rm -rf /Library/Developer/CommandLineTools and reinstall it xcode-select --install.

    0 讨论(0)
提交回复
热议问题