C code can be written in any platform like Mac, Windows, etc. C compilers compile C code and create an executable according to the platform.
The name of the C compiler (that was installed along with the command line tools) is gcc. To check that this is now successfully installed, enter "gcc --version" at the prompt.
Make sure you have downloaded the latest 'Command Line Tools' package and run this from a terminal (command line):
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
For some information on Catalina, see Can't compile a C program on a Mac after upgrading to Catalina 10.15.
Extracting a semi-coherent answer from rather extensive commentsโฆ
Very often, xcode-select --install
has been the correct solution, but it does not seem to help this time. Have you tried running the main Xcode GUI interface? It may install some extra software for you and clean up. I did that after installing Xcode 10.0, but a week or more ago, long before upgrading to Mojave.
I observe that if your GCC is installed in /usr/local/bin
, you probably aren't using the GCC from Xcode; that's normally installed in /usr/bin
.
I too have updated to macOS 10.14 Mojave and Xcode 10.0. However, both the system /usr/bin/gcc
and system /usr/bin/clang
are working for me (Apple LLVM version 10.0.0 (clang-1000.11.45.2) Target: x86_64-apple-darwin18.0.0
for both.) I have a problem with my home-built GCC 8.2.0 not finding headers in /usr/include
, which is parallel to your problem with /usr/local/bin/gcc
not finding headers either.
I've done a bit of comparison, and my Mojave machine has no /usr/include
at all, yet /usr/bin/clang
is able to compile OK. A header (_stdio.h
, with leading underscore) was in my old /usr/include
; it is missing now (hence my problem with GCC 8.2.0). I ran xcode-select --install
and it said "xcode-select: note: install requested for command line developer tools
" and then ran a GUI installer which showed me a licence which I agreed to, and it downloaded and installed the command line tools โ or so it claimed.
I then ran Xcode GUI (command-space, Xcode, return) and it said it needed to install some more software, but still no /usr/include
. But I can compile with /usr/bin/clang
and /usr/bin/gcc
โ and the -v
option suggests they're using
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Then Maxxx noted:
I've found a way. If we are using Xcode 10, you will notice that if you navigate to the
/usr
in the Finder, you will not see a folder called 'include' any more, which is why the terminal complains of the absence of the header files which is contained inside the 'include' folder. In the Xcode 10.0 Release Notes, it says there is a package:/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
and you should install that package to have the
/usr/include
folder installed. Then you should be good to go.
When all else fails, read the manual or, in this case, the release notes. I'm not dreadfully surprised to find Apple wanting to turn their backs on their Unix heritage, but I am disappointed. If they're careful, they could drive me away. Thank you for the information.
Having installed the package using the following command at the command line, I have /usr/include
again, and my GCC 8.2.0 works once more.
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
As Vesal points out in a valuable comment, you need to download the Command Line Tools package for Xcode 10.1 on Mojave 10.14, and you can do so from:
You need to login with an Apple ID to be able to get the download. When you've done the download, install the Command Line Tools package. Then install the headers as described in the section 'Working Solution'.
This worked for me on Mojave 10.14.1. I must have downloaded this before, but I'd forgotten by the time I was answering this question.
On or about 2019-05-17, I updated to Mojave 10.14.4, and the Xcode 10.2 command line tools were also upgraded (or Xcode 10.1 command line tools were upgraded to 10.2). The open
command shown above fixed the missing headers. There may still be adventures to come with upgrading the main Xcode to 10.2 and then re-reinstalling the command line tools and the headers package.
On 2019-07-22, I got notice via the App Store that the upgrade to Xcode 10.3 is available and that it includes SDKs for iOS 12.4, tvOS 12.4, watchOS 5.3 and macOS Mojave 10.14.6. I installed it one of my 10.14.5 machines, and ran it, and installed extra components as it suggested, and it seems to have left /usr/include
intact.
Later the same day, I discovered that macOS Mojave 10.14.6 was available too (System Preferences โถ Software Update), along with a Command Line Utilities package IIRC (it was downloaded and installed automatically). Installing the o/s update did, once more, wipe out /usr/include
, but the open
command at the top of the answer reinstated it again. The date I had on the file for the open
command was 2019-07-15.
The upgrade to XCode 11.0 ("includes Swift 5.1 and SDKs for iOS 13, tvOS 13, watchOS 6 and macOS Catalina 10.15") was released 2019-09-21. I was notified of 'updates available', and downloaded and installed it onto machines running macOS Mojave 10.14.6 via the App Store app (updates tab) without problems, and without having to futz with /usr/include
. Immediately after installation (before having run the application itself), I tried a recompilation and was told:
Agreeing to the Xcode/iOS license requires admin privileges, please run โsudo xcodebuild -licenseโ and then retry this command.
Running that (sudo xcodebuild -license
) allowed me to run the compiler. Since then, I've run the application to install extra components it needs; still no problem. It remains to be seen what happens when I upgrade to Catalina itself โ but my macOS Mojave 10.14.6 machines are both OK at the moment (2019-09-24).
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.
When you
Mojave 10.14.6
/usr/include
was deleted againThe file /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg does not exist.
andxcode-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
.
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.
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.
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.
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.
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
โ๐the real error๐โ
/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk' [-Wmissing-sysroot]
In file included from psycopg/psycopgmodule.c:27:
In file included from ./psycopg/psycopg.h:34:
/opt/local/Library/Frameworks/Python.framework/Versions/3.6/include/python3.6m/Python.h:25:10: fatal error: 'stdio.h' file not found
โ๐ what I thought was the error ๐โ
#include <stdio.h>
^~~~~~~~~
1 error generated.
It appears you are missing some prerequisite to build the package
xcode-select --install
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
Still the same error on stdio.h.
which exists in a number of places:
(venv) jluc@bemyerp$ mdfind -name stdio.h
/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/stdio.h
/usr/include/_stdio.h
/usr/include/secure/_stdio.h
/usr/include/stdio.h โ
๐ I believe this is the one that's usually missing.
but I have it.
/usr/include/sys/stdio.h
/usr/include/xlocale/_stdio.h
clang
is complaining about and look:(venv) jluc@gotchas$ cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
(venv) jluc@SDKs$ ls -l
total 0
drwxr-xr-x 8 root wheel 256 Aug 29 23:47 MacOSX.sdk
drwxr-xr-x 4 root wheel 128 Aug 29 23:47 DriverKit19.0.sdk
drwxr-xr-x 6 root wheel 192 Sep 11 04:47 ..
lrwxr-xr-x 1 root wheel 10 Oct 1 13:28 MacOSX10.15.sdk -> MacOSX.sdk ๐
drwxr-xr-x 5 root wheel 160 Oct 1 13:34 .
Hah, we have a symlink for MacOSX10.15.sdk, but none for MacOSX10.14.sdk. Here's my first clang
error again:
clang: warning: no such sysroot directory: '/Applications/Xcode.app/.../Developer/SDKs/MacOSX10.14.sdk' [-Wmissing-sysroot]
My guess is Apple jumped the gun on their xcode config and are already thinking they're on Catalina. Since it's a new Mac, the old config for 10.14 is not in place.
Let's symlink 10.14 the same way as 10.15:
ln -s MacOSX.sdk/ MacOSX10.14.sdk
btw, if I go to that sdk directory, I find:
...
./usr/include/sys/stdio.h
./usr/include/stdio.h
....
pip install psycopg2
works.
Note: the actual pip install command made no reference to MacOSX10.14.sdk, that came at a later point, possibly by the Python installation mechanism introspecting the OS version.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With