What the different between SRCROOT and PROJECT_DIR?

IosXcodeEnvironment Variables

Ios Problem Overview


In Xcode, we have to configure many paths in the Build Settings, then we will deal with the $(SRCROOT) and $(PROJECT_DIR) , But what the difference between them, can you show me an example, thx a lot.

Ios Solutions


Solution 1 - Ios

Exchangeable in practice, while the documentation makes these subtle theoretical distinctions:

  1. SRCROOT
    >Directory path. Identifies the directory containing the target’s source files: contains the path to the project file that defines the target.

SOURCE_ROOT is an undocumented alias to SRCROOT 2. PROJECT_DIR
Identifies the directory containing the project (.xcodeproj)
$(PROJECT_DIR)/build is used as the create the default value for:

  • Intermediate Build Files Path OBJROOT
  • Build Products Path SYMROOT

>Typically these paths are not set per target, but are set per-project or per-user.

  1. PROJECT_FILE_PATH
    Identifies the project itself.
    Equivalent to $(PROJECT_DIR)/$(PROJECT_NAME).xcodeproj

Conceptually different (#1 is about the project which defines the target while #2 is about the project independently of any target), they are always pointing to the same location since you are, in essence, always building a target.

References

Xcode 8.3 Build Settings reference
Xcode Build System Guide (Retired 2016-09-29)

Solution 2 - Ios

SRCROOT & PROJECT_DIR are same macros have same effect.PROJECT_DIR makes more sense when talking about frameworks.

Solution 3 - Ios

$ (SRCROOT) represents the project root directory. like this is a relative path, SRCROOT should be used

enter image description here

enter image description here

$ (PROJECT_DIR) represents the entire project. should use PROJECT_DIR to the first test01, which represents the outermost folder of the project

enter image description here

When adding files to the project, such as .a, etc., first showinfinder, copy it to the project, and then drag it to the xcode project

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionchildrenOurFutureView Question on Stackoverflow
Solution 1 - IosSwiftArchitectView Answer on Stackoverflow
Solution 2 - IosBaigView Answer on Stackoverflow
Solution 3 - IosParesh MangukiyaView Answer on Stackoverflow