Installing RStan on Mojave Mac OS X. Issue with C++ toolchain

Ultimately I want to use brm() function in “brms” (which, as I understand, delegates to RStan). When I call brm() I get the following error message:

Compiling the C++ model
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! dyld: Library not loaded: @rpath/DVTFoundation.framework/Versions/A/DVTFoundation
Referenced from: /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild
Reason: no suitable image found. Did find:
/Applications/Xcode.app/Contents/Developer/usr/bin/…/…/…/SharedFrameworks/DVTFoundation.framework/Versions/A/DVTFoundation: cannot load ‘/Applications/Xcode.app/Contents/Developer/usr/bin/…/…/…/SharedFrameworks/DVTFoundation.framework/Versions/A/DVTFoundation’ because Objective-C garbage collection is not supported
xcrun: error: unable to locate xcodebuild, please make sure the path to the Xcode folder is set correctly!
xcrun: error: You can set the path to the Xcode folder using /usr/bin/xcode-select -switch
In addition: Warning messages:
1: In system2(file.path(R.home(component = “bin”), “R”), args = paste(“CMD config”, :
running command ‘’/Library/Frameworks/R.framework/Resources/bin/R’ CMD config CXX14 2>/dev/null’ had status 69
2: In .fun(model_code = .x1) :
C++ compiler not found on system. If absent, see
https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started
3: In system(cmd, intern = !verbose) :

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! dyld: Library not loaded: @rpath/DVTFoundation.framework/Versions/A/DVTFoundation
Referenced from: /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild
Reason: no suitable image found. Did find:
/Applications/Xcode.app/Contents/Developer/usr/bin/…/…/…/SharedFrameworks/DVTFoundation.framework/Versions/A/DVTFoundation: cannot load ‘/Applications/Xcode.app/Contents/Developer/usr/bin/…/…/…/SharedFrameworks/DVTFoundation.framework/Versions/A/DVTFoundation’ because Objective-C garbage collection is not supported
xcrun: error: unable to locate xcodebuild, please make sure the path to the Xcode folder is set correctly!
xcrun: error: You can set the path to the Xcode folder using /usr/bin/xcode-select -switch