XCode: Is there a way to clear DYLD_LIBRARY_PATH?

I want my application to run the same inside and outside of XCode. The issue is DYLD_LIBRARY_PATH is causing the wrong libraries to be found when running my executable. Is there a way to clear it? My attempts to try and clear it only appended to the process environment variable. Also, how exactly is it determined? I am not explicitily setting it. I am using CMake.


Thank you,

Kris Berg

Accepted Reply

I want my application to run the same inside and outside of Xcode.

FYI, this overall goal is infeasible. When you run from Xcode you run in the debugger, and that changes lots of different things, with

DYLD_LIBRARY_PATH
being just one part of that.

Also, how exactly is it determined?

Xcode explicitly sets to include two elements:

  • Your build directory — This enables the common case of a project (or workspace) that builds an app and a library that you want to debug together. It ensures that the app loads the built version of your library rather than some other version installed elsewhere on the system. This is useful in general, and particularly useful for folks working on the OS itself (-:

  • /usr/lib/system/introspection
    — This directory includes debug versions of various
    libSystem
    subcomponents, which allows Xcode to hook into those subcomponents for debugging purposes. For example, the Product > Scheme > Edit Scheme > Run > Options > Queue Debugger feature depends on this.

I don’t think there’s any way to clear these entries. Certainly, adding the

DYLD_LIBRARY_PATH
environment variable in the scheme editor results in these entries being prepended on to the entries that you set.

One easy solution is to run your code outside of Xcode and then attach to it (Debug > Attach to Process), but that isn’t appropriate in all situations. Another option would be to not put these problematic libraries in your build directory in the first place; that seems like something that CMake should be capable of.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Replies

I want my application to run the same inside and outside of Xcode.

FYI, this overall goal is infeasible. When you run from Xcode you run in the debugger, and that changes lots of different things, with

DYLD_LIBRARY_PATH
being just one part of that.

Also, how exactly is it determined?

Xcode explicitly sets to include two elements:

  • Your build directory — This enables the common case of a project (or workspace) that builds an app and a library that you want to debug together. It ensures that the app loads the built version of your library rather than some other version installed elsewhere on the system. This is useful in general, and particularly useful for folks working on the OS itself (-:

  • /usr/lib/system/introspection
    — This directory includes debug versions of various
    libSystem
    subcomponents, which allows Xcode to hook into those subcomponents for debugging purposes. For example, the Product > Scheme > Edit Scheme > Run > Options > Queue Debugger feature depends on this.

I don’t think there’s any way to clear these entries. Certainly, adding the

DYLD_LIBRARY_PATH
environment variable in the scheme editor results in these entries being prepended on to the entries that you set.

One easy solution is to run your code outside of Xcode and then attach to it (Debug > Attach to Process), but that isn’t appropriate in all situations. Another option would be to not put these problematic libraries in your build directory in the first place; that seems like something that CMake should be capable of.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"