How to accept Xcode license?

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.


Solution 1:

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

Solution 2:

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.

Solution 3:

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

Solution 4:

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.