1

I recently switched from windows to mac os and started using xcode as a c++ development environment, I'm still learning, so I don't know how to compile and output the results of the written code to the command line/terminal

все перегулял ничо не нашел

2
  • Why would you use Xcode as "development environment" and at the same want to "compile and output the results on command line"? Xcode has a shiny "run" button you can push. Commented Feb 10, 2023 at 12:53
  • I wrote a simple toy that works on the command line, I tried to compile it and run it already on Mac os via Xcode, but here it turned out to be much more difficult to do Commented Feb 10, 2023 at 13:10

1 Answer 1

2

To compile code in the terminal just use ls and cd to go to your source dir and use the command

clang++ source.c -o output

and to run it use:

./output

I suppose you got xcode command line tools installed, if not, use the command xcode-select --install. Also on macos there isn't gcc in xcode (the command gcc is a alias to clang), to get gcc, get brew and install gcc with brew install gcc and use it as gcc-12

Sign up to request clarification or add additional context in comments.

9 Comments

Of course, it's not as convenient as on windows, everything works there in Visual Studio through the Run button, but thank you anyway!
Woah you mean windows is more convenient :O Unix stuff is certainly better when you get stuff right (like using oh my zsh for autocomplete, use iTerm...)
If you want a auto build button you can try out CLion, 'Sublime text` or Vscode (I don't really like vscode :P) I don't really like XCode since it's too heavy, it is mainly only used for developing ios and (some) macos applications
Yes, I wasn't going to seriously use Xcode to program in c++, I just wanted to run my first program on Mac os, just to remember it. Now I'm trying to deal with Mac os analogues of getch() and system("cls"), which I used in Windows.
XCode has a built-in console (it's at the bottom of the window). You can edit the Scheme to use Terminal instead of the XCode console.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.