Supplying Launch Arguments for Command-Line Programs
If you look at the main() function in a C, C++, or Objective C program, you will see that main() takes two arguments: argc and argv. Java programs have one argument in main(): args. These arguments let you supply arguments to your program when it launches. If you wrote a program to play an audio file, you could supply the name of the file to play as a launch argument.
When you launch a command-line program from the Terminal application, you type the launch arguments as you launch the program. Xcode lets you run and debug command-line programs inside Xcode so you don't have to run the Terminal application. How do you supply the launch arguments from Xcode?
- Select the executable from the Groups and Files list.
- Click the Info button in the project window toolbar to open the executable's information panel.
- Click the Arguments tab in the information panel.
- At the top of the information panel, you will see a section titled Arguments to be passed on launch. This section is where you add the launch arguments. Click the + button to add the arguments.
Changing the Executable Name
When you create an Xcode application project, Xcode uses the project name as the name of the executable file. How do you change the name of the executable file? Change the target's Product Name build setting, which is part of the Packaging collection.
- Select the target from the Groups and Files list.
- Click the Info button in the project window toolbar to open the target's information panel.
- Click the Build tab in the information panel.
- Choose Packaging from the Collection pop-up menu.
- Enter the desired executable file name as the value for the Product Name build setting.
If you want to change the executable file name for all build configurations, make sure you choose All Configurations from the Configuration pop-up menu when you're changing the executable name. If you want to change the executable name for a single build configuration (Example: adding the word Debug to the executable name for the debug configuration), select that configuration from the Configuration pop-up menu.