Xcode command line tool - how to run in terminal?

后端 未结 3 689
猫巷女王i
猫巷女王i 2021-02-14 03:00

When you create a Command Line Tool project in Xcode you get this, in main.m:

#import 

int main(int argc, const char * argv[])
{
         


        
相关标签:
3条回答
  • 2021-02-14 03:14

    In Xcode 9 you can try the following (works for me in June 2018):

    1. instead of 'edit scheme' click 'new scheme', give it a name and save
    2. now choose that new scheme you've just created and click 'edit scheme'
    3. go to the 'Info' tab and in a menu 'Executable' choose 'Other...'
    4. in file window go to search input field and type 'terminal' and click on its icon when you find it. Now you should see 'Terminal.app' in 'Executable' field
    5. go to the 'Arguments' tab, click on + and copy and paste this line there: ${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}
    6. click 'close' and run your program with your new scheme selected

    Normally Xcode will open terminal for you. If not, you may also turn off any debug related fields in the 'Info' tab. Hope this helps!

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

    0 讨论(0)
  • 2021-02-14 03:15

    Assuming your executable is named "my_program", and it's in the "/foo/bar/Debug" directory:

    cd /foo/bar
    ./my_program
    

    If you aren't sure how to find the program file itself, you can right-click it (i.e.: the "product") and "Show in Finder" as shown in this screenshot:

    enter image description here

    0 讨论(0)
  • 2021-02-14 03:16

    You can have the terminal launch everytime you run the application through editing the scheme. I believe this became available from Xcode 8.0.

    1. Access Edit Scheme

    2. Switch Console from Use Xcode to Use Terminal

    0 讨论(0)
提交回复
热议问题