Xcode command line tool - how to work in terminal?

When you create a command line tool project in Xcode, you get this, in main.m:

#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... NSLog(@"Hello, World!"); } return 0; } 

I can run this from Xcode. But I want to compile it so that I can run it from Terminal. What are the steps?

+6
source share
3 answers

Assuming your executable has the name "my_program" and it is in the directory "/ foo / bar / Debug":

 cd /foo/bar ./my_program 

If you don’t know how to find the program file, you can right-click it (for example, “product”) and “Show in Finder”, as shown in this screenshot:

enter image description here

+9
source

You can launch the terminal every time you launch the application by editing the circuit. I believe this has become available with Xcode 8.0.

  • Edit Scheme Access

    Change Scheme

  • Switch Console from Use Xcode to Use Terminal

    Console

+3
source

In Xcode 9, you should do the following:

  • instead of the “editing scheme” click “new scheme”, give it a name and save
  • now select the new scheme you just created and click on the "edit" scheme '
  • go to the "Information" tab and in the "Executable" menu select "Other ..."
  • in the file window, go to the search input field and enter "terminal" and click on the icon when you find it. You should now see "Terminal.app" in the "Executable file" field
  • go to the "Arguments" tab, click "+" and copy and paste this line there: ${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}
  • click "close" and run your program with your new scheme.

Typically, Xcode will open a terminal for you. If not, you can also disable all debugging-related fields on the Information tab. Hope this helps!

Full tutorial is here: https://www.raywenderlich.com/163134/command-line-programs-macos-tutorial-2

+1
source

Source: https://habr.com/ru/post/956606/


All Articles