11

I am using a mac version 10.13.6.

I want to compile C programs through the terminal. I've downloaded Xcode and the command line tools. When I type clang --version in the terminal, I get the following two error messages:

clang: error: unable to locate xcodebuild, please make sure the path to the Xcode folder is set correctly!

clang: error: You can set the path to the Xcode folder using /usr/bin/xcode-select -switch

I did some googling and found a fix here. The solution is to run the following line in terminal:

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

Which I did. But when I enter clang --version after doing this, I get exactly the same two errors. What's going on?

NB: very very new to this so please keep that in mind when answering! cheers

Community
  • 1
  • 1
ctt25
  • 121
  • 1
  • 1
  • 6
  • What made you use `/Applications/Xcode.app/Contents/Developer` instead of `/Library/Developer/CommandLineTools/`? – YiFei Sep 28 '18 at 23:21
  • Because that directory doesn't exist in my computer. Initially I looked for that. But then I tried typing xcode-select -p (which I found at https://stackoverflow.com/a/15371967), which returns /Applications/Xcode.app/Contents/Developer. – ctt25 Sep 28 '18 at 23:30
  • I just tried what you said and it worked! I have no idea why. But thank you! – ctt25 Sep 28 '18 at 23:34
  • Things have changed over time. You could try `xcode-select --install`; that may do the job for you. Sometimes, running the XCode GUI will download and install some extra software. With XCode 10.0, you may need to install the extra package mentioned in [Can't compile C program on a Mac after upgrade to Mojave](https://stackoverflow.com/questions/52509602/cant-compile-c-program-on-a-mac-after-upgrade-to-mojave) — which isn't directly your problem since you're still using macOS 10.13.6 High Sierra, but it may still be relevant. Read the XCode 10 release notes (link in the answer); they may help. – Jonathan Leffler Sep 28 '18 at 23:44
  • @JonathanLeffler thanks for this. I recently updated to Mojave and this was very useful! – ctt25 Oct 03 '18 at 09:09

1 Answers1

12
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer 

worked like a charm for me

AdamWinsche
  • 129
  • 4