Xcode Arguments Passed On Launch won't load

I am building and running a simple Open MPI C application.
In order to run it, I configured the run process in this way:\

  1. Edit Scheme -> Run -> Info -> Executable -> Other... -> /path/to/mpiexec
  2. Edit Scheme -> Run -> Arguments -> Arguments Passed On Launch -> -np 4 "$(BUILT_PRODUCTS_DIR)/$(EXECUTABLE_NAME)"

Now, instead of the hardcoded "4" as the number of processes, I want to specify an environment variable (like the already existing BUILT_PRODUCTS_DIR and EXECUTABLE_NAME environment variables), so I enter in Environment Variables NUM_PROCS as Name and 4 as Value.

Thus, I write in Arguments Passed On Launch the whole quoted string:
"-np" "$(NUM_PROCS)" "$(BUILT_PRODUCTS_DIR)/$(EXECUTABLE_NAME)".
And Xcode can't read the NUM_PROCS environment variable (despite I can easily read it in the C program by a getenv("NUM_PROCS")!), in fact, it runs the default number of processes of my system (12).

I tried in a very large number the different ways of writing arguments (every string on a new line, with quotes, without quotes, ...), but none worked as I expected.

M3 Pro, macOS Sequoia 15.0.1 Xcode 16.0

I see what you're seeing, but I don't agree with your expectation.

BUILT_PRODUCTS_DIR and EXECUTABLE_NAME are not environment variables, they are Xcode build settings.

The environment Xcode launches your tool into is empty, aside from the variables you set in the Environment Variables section of the Scheme settings. In my Terminal, I can echo $HOMEBREW_PREFIX and the result is /opt/homebrew. However, the result of getenv("HOMEBREW_PREFIX") in my program is null, if I run it from Xcode, but it is /opt/homebrew if I run it from an interactive shell, because that shell runs its programs in a non-empty environment.

If you just want to debug your application, using the environment it would have if run at the command line in a shell on your machine, you can go the Scheme's Info tab, and select "wait for the executable to be launched". Then launch it from a Terminal window - it will get whatever environment your shell gives it.

...

Xcode Arguments Passed On Launch won't load
 
 
Q