60

I want to install a C based toolbox on MATLAB software. To do this, I need to install the GCC compiler. I think I have done that already. And I have Xcode too.

To setup the toolbox, I need to write mex -setup; in the MATLAB command window. I've got the following warning and don't know how to solve it:

Warning: Xcode is installed, but its license has not been accepted. Run Xcode and accept its license agreement.

Error using mex
No supported compiler or SDK was found. For options, visit http://www.mathworks.com/support/compilers/R2014a/maci64.

Glorfindel
  • 4,057
SAH
  • 798

6 Answers6

109

In Terminal:

sudo xcodebuild -license

Which should view/accept it on behalf of all accounts on that particular Mac.

In recent Xcode versions you are able to accept it in one step:

sudo xcodebuild -license accept
user3439894
  • 58,676
TJ Luoma
  • 20,659
  • 2
    Running xcodebuild -license from the command line (without sudo) yields the error Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo., so I think the sudo is needed. – D.W. Dec 23 '15 at 00:24
  • 7
    In recent XCode versions you can also use sudo xcodebuild -license accept to avoid manual input. – Ohad Schneider Feb 02 '16 at 13:04
  • 2
    @OhadSchneider Thanks for the tip. I wonder exactly what purpose this serves, legally.. Not that people actually read the ToS, but XCode having something where you can set up a script to blindly accept a legal agreement makes it feel like it'd be hard to actually enforce the terms in court. – Andrew Theken Mar 25 '16 at 12:57
  • 1
    So the answer to the above thing since there's a stack overflow bug that prevents me from editing it is that Xcode -license accept doesn't send out any network packets but instead modifies a file on disk. You may need to go to https://developer.apple.com/account and accept it there instead. Then you'll need to restart Xcode since it can't figure this side channel solution. This bug-filled dance would be hilarious if it didn't take me over an hour to figure it out. – kristopolous Oct 11 '16 at 21:39
  • @Electricman this should be the accepted answer – rexford Jun 25 '18 at 12:14
  • A fine example of how Apple really drop the ball in UX. The legal document says 'type agree to agree' and fails to mention the sudo xcodebuild -license that should preceed it. It is unclear whether one should type agree prior to scrolling the last line of the document at which point you are kicked back to the command line where agree means nothing. – straya Dec 11 '20 at 05:05
  • In Terminal: sudo xcodebuild -license Which should view/accept it on behalf of all accounts on that particular Mac. In recent Xcode versions you are able to accept it in one step: sudo xcodebuild -license accept Works using macOS Catalina 10.15 and Xcode 11.5. – oknkuwum Jul 07 '20 at 10:05
10

You need to start/open Xcode once to accept the license agreement. Easiest way to run the application is by clicking on the Spotlight icon on top right and just type its name.

nohillside
  • 100,768
  • 2
    I've opened it already. But I didn't ask me anything. :( I also, created a project too. @patrix – SAH Mar 02 '15 at 16:30
  • 1
    @Electricman If you open terminal and type these two commands what are your results? sudo xcode-select -r and sudo xcode-select --install (and if it says you should run Software Update, check there are no Xcode pending updates with sudo softwareupdate -l – bmike Mar 02 '15 at 16:41
  • 1
    I wrote sudo xcode-select -r and sudo xcode-select --install and a window has been appeared saying the xcode selected command requires the command line developer tools. would u like to install the tools now with three button including, not now, get xcode and install. So, I selected install Xcode and accepted the licence, and then another boxed opened finding software that says cant install the software be it is not currently available from the software update server. what should I do? @bmike Also, sudo softwareupdate -l shows nothing about xcode needs for updates – SAH Mar 02 '15 at 16:52
  • 1
    @Electricman Odd - is this computer managed by a corporate IT department? Is your log in user an Admin user? If so, I'd make a new admin test account and re-run the Xcode commands - it could be simply your user or permissions are wonky. Hard to tell without sitting at that computer. The commands should get you all the permissions you need. Worst case, install all the updates and try again with the new user. – bmike Mar 02 '15 at 17:04
  • It is a Admin user. I made a new admin account but got a different error too. very bad situation @bmike – SAH Mar 02 '15 at 17:27
  • xcode-select -p gave the follwoing output /Library/Developer/CommandLineTools. meaning that I have its latest version already. @bmike – SAH Mar 02 '15 at 17:53
  • You might want to make a backup and consider starting over with a clean install if you are wasting more time with this than it would take to try a clean install. @Electricman the -p doesn't really tell much and the -r is useful diagnostic to check the app is installed properly. Once your backup is complete, consider deleting Xcode and reinstalling from the MAS. – bmike Mar 03 '15 at 00:55
  • This does not work. Even if you accept the xcode license, you still have to install the command line tools separately, open a terminal, and accept the license for the command line tools. TJ Luoma's answer (http://apple.stackexchange.com/a/213151/101532) is correct. – DaveParillo Dec 11 '15 at 21:50
2

You can also do this from the command line sudo xcrun cc

Steve Tauber
  • 192
  • 7
2

If you have only the Command Line Tools installed (and you don't want the full Xcode), the solution is a bit trickier. From my saver here, run the following (no sudo needed) and the mex -setup command will work like a charm. Here I use the current version 13.0 at the time of writing, to be adapted.

defaults write com.apple.dt.Xcode IDEXcodeVersionForAgreedToGMLicense 13.0
jmon12
  • 121
  • to get the version I had to do this: https://stackoverflow.com/a/42144725/764365 – Jimbo Nov 26 '22 at 05:33
  • @Jimbo It might be that the version is the SDK version instead of the version you extracted. I'm not sure at all, but in my case, the pkgutil command you mentioned to gives me '14.1.xxxxx', but the highest version of SDKs I have is 13.0 (in /Library/Developer/CommandLineTools/SDKs)... Not sure what IDEXcodeVersionForAgreedToGMLicense exactly refers to and whether it really matters to trick mex. – jmon12 Nov 27 '22 at 15:40
0

If you don't have XCode installed, you can download it from Apple Developer or the App Store.

I had to do the Clover-Space, type xcode (Which pulled up XCode-Beta), and press Clover-Enter to open the file location. I found that my XCode was still in the "Downloads" folder.

So I drag/dropped it onto the Applications folder, then I ran: Download Xcode or move it to your Applications folder. Then, open terminal and run both of these commands. One after the other.

sudo xcode-select -s /Applications/Xcode-Beta.app/Contents/Developer

sudo xcodebuild -license

Then space-down to the bottom and type "agree"

Suamere
  • 101
  • bret7600, if you want to answer with your answer, create a new answer. You completely removed the whole point of my answer. If you want to edit somebody's answer, add clarity. Don't rewrite the whole thing. – Suamere Oct 25 '16 at 13:11
  • I'm assuming [Apple Developer][1] is supposed to be a link? – tubedogg Oct 25 '16 at 21:21
  • @tubedogg Thanks, must have gotten cut off in the edit. – Suamere Oct 25 '16 at 21:28
0

You must accept the XCode license. If you don't have XCode installed / don't need the application, you can instead just install the developer tools, which will also complete the license agreement:

# Install Command Line Tools
xcode-select --install

# Enable command line tools
sudo xcode-select --switch /Library/Developer/CommandLineTools

Source: https://github.com/nodejs/node-gyp/issues/569

Jake
  • 121