Home > OS >  Compile and execute cpp in xcode, and add additional execution instructions, Such as iconv command
Compile and execute cpp in xcode, and add additional execution instructions, Such as iconv command

Time:12-01

Sorry, I'm new to Xcode and not very familiar with it, I use Xcode (command line tool project with external build system) to compile cpp files and automatically execute cpp unix executable files. After the program is compiled (command R), I set the settings as shown in the screenshot below to automatically execute. Is there any way for me to execute also add additional commands? Such as iconv.

my scheme settings

The following line is what I ultimately want to execute. ./myFile argument1 | iconv -f big5

But my Xcode looks like it's executing only ./myFile argument1

really thanks

CodePudding user response:

On the same place where you setup the build scheme, you can also add a post-build script.

  • Go to the left of the panel, and expand Build
  • Select Post-actions
  • Near the bottom center, click on -> New Run Script Action
  • Add script like you would run them in terminal
    • Note the current directory will not be where the project is built
    • You can use ${TARGET_BUILD_DIR} macro for the build directory
  • Note, you want to make sure to select your current project at the Provide build settings from so it can import the correct path macros like TARGET_BUILD_DIR

A screenshot of adding a post-build script: Screenshot of adding a post-build script

*Older versions of Xcode might have different GUI, but the idea should be about the same.


  • Sidenote, ⌘R is really for running the program within Xcode, consider using ⌘B.
  • Related