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

前端 未结 15 671
陌清茗
陌清茗 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:26

    Be sure to check Xcode Preferences -> Locations.

    The Command Line Tools I had selected was for the previous version of Xcode (8.2.1 instead of 10.1)

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

    ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk' might help you. It fixed my problem.

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

    NOTE: The following is likely highly contextual and time-limited before the switch/general availability of macos Catalina 10.15. New laptop. I am writing this Oct 1st, 2019.

    These specific circumstances are, I believe, what caused build problems for me. They may not apply in most other cases.

    Context:

    • macos 10.14.6 Mojave, Xcode 11.0, right before the launch of macos Catalina 10.15. Newly purchased Macbook Pro.

    • failure on pip install psycopg2, which is, basically, a Python package getting compiled from source.

    • I have already carried out a number of the suggested adjustments in the answers given here.

    My errors:

    pip install psycopg2
    Collecting psycopg2
      Using cached https://files.pythonhosted.org/packages/5c/1c/6997288da181277a0c29bc39a5f9143ff20b8c99f2a7d059cfb55163e165/psycopg2-2.8.3.tar.gz
    Installing collected packages: psycopg2
      Running setup.py install for psycopg2 ... error
        ERROR: Command errored out with exit status 1:
         command: xxxx/venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/bk/_1cwm6dj3h1c0ptrhvr2v7dc0000gs/T/pip-install-z0qca56g/psycopg2/setup.py'"'"'; __file__='"'"'/private/var/folders/bk/_1cwm6dj3h1c0ptrhvr2v7dc0000gs/T/pip-install-z0qca56g/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/bk/_1cwm6dj3h1c0ptrhvr2v7dc0000gs/T/pip-record-ef126d8d/install-record.txt --single-version-externally-managed --compile --install-headers xxx/venv/include/site/python3.6/psycopg2
    
    
    ...
    /usr/bin/clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -pipe -Os -isysroot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -DPSYCOPG_VERSION=2.8.3 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=90615 -DHAVE_LO64=1 -I/Users/jluc/kds2/py2/venv/include -I/opt/local/Library/Frameworks/Python.framework/Versions/3.6/include/python3.6m -I. -I/opt/local/include/postgresql96 -I/opt/local/include/postgresql96/server -c psycopg/psycopgmodule.c -o build/temp.macosx-10.14-x86_64-3.6/psycopg/psycopgmodule.o
    
        clang: warning: no such sysroot directory: 
    '/Applications/Xcode.app/Contents/Developer/Platforms
                                  ❌                                                                    
    0 讨论(0)
  • 2020-11-22 07:33

    Had similar problems as the OP

    Issue

    cat hello.c

    #include <stdlib.h>
    int main() { exit(0); }
    

    clang hello.c

    /usr/local/include/stdint.h:2:10: error: #include nested too deeply
    etc...
    

    Attempted fix

    I installed the latest version of XCode, however, release notes indicated the file mentioned in the previous fix, from Jonathan here, was no longer available.

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

    Details here https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes , under the New Features section.


    Solution that worked for me...

    Using details in this comment, https://github.com/SOHU-Co/kafka-node/issues/881#issuecomment-396197724

    I found that brew doctor reported I had unused includes in my /usr/local/ folder.

    So to fix, I used the command provided by user HowCrazy , to find the unused includes and move them to a temporary folder.

    Repeated here...

    mkdir /tmp/includes
    brew doctor 2>&1 | grep "/usr/local/include" | awk '{$1=$1;print}' | xargs -I _ mv _ /tmp/includes
    

    After running the scripts, the include file issue was gone. nb: I commented on this issue here too.

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

    I tried almost all the posted solutions and nothing worked for me. I use Mojave OS (10.14.6) and what finally worked for me (after removing and re-installing Xcode and CLTs and SDK headers):

    1. Install Clang v8 from https://cran.r-project.org/bin/macosx/tools/
    2. Modify the following lines from ~/.R/Makevars file
    CC=/usr/local/opt/llvm/bin/clang -fopenmp
    CXX=/usr/local/opt/llvm/bin/clang++
    

    with

    CC=/usr/local/clang8/bin/clang -fopenmp
    CXX=/usr/local/clang8/bin/clang++
    

    Now R packages that rely on C compilers install successfully

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

    apue.h dependency was still missing in my /usr/local/include after I managed to fix this problem on Mac OS Catalina following the instructions of this answer

    I downloaded the dependency manually from git and placed it in /usr/local/include

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