xcode 路径

$(SRCROOT)宏和$(PROJECT_DIR)宏

XCode环境变量及路径设置

分类: Objective-C2013-03-11 12:30 41336人阅读 评论(1) 收藏 举报 一般我们在xcode里面配置包含工程目录下头文件的时候,都要关联着相对路径和绝对路径,如果只是自己用这个项目,用绝对路径的问题不大,但是如果你把 工程发给别人,别人就要在改这个绝对路径,这时候绝对路径的缺点立马出现。

所以在修改User Header Search Paths这个选项的时候使用
"$(SRCROOT)/当前工程名字/需要包含头文件所在文件夹"
将上面的双引号里面的字符串拷贝之后,你会发现这个“$(SRCROOT)”,会自动变成当前工程所以的目录。

这样就可以了,发给别人,别人也不用在去修改路径了。

xcode4的环境变量,Build Settings参数,workspace及联编设置

一、xcode4中的环境变量

?


1

$(BUILT_PRODUCTS_DIR)

build成功后的,最终产品路径--可以在Build Settings参数的Per-configuration Build Products Path项里设置

?


1

$(TARGET_NAME)

目标工程名称

?


1

$(SRCROOT)

工程文件(比如Nuno.xcodeproj)的路径

?


1

$(CURRENT_PROJECT_VERSION)

当前工程版本号

其他:

当编译静态库,设备选模拟器(iPhone 5.0 Simulator),未设置任何Build Settings参数时,默认的基础路径:

/Users/xxx/Library/Developer/Xcode/DerivedData/xxxWorkspace-caepeadwrerdcrftijaolkkagbjf

下面用$()代替上面一长串东东

$(SYMROOT) = $()/Build/Products

$(BUILD_DIR) = $()/Build/Products

$(BUILD_ROOT) = $()/Build/Products

这三个变量中的$()不会随着Build Settings参数的设置而改变

相反,以下可以通过设置而改变

$(CONFIGURATION_BUILD_DIR) = $()/Build/Products/Debug-iphonesimulator

$(BUILT_PRODUCTS_DIR) = $()/Build/Products/Debug-iphonesimulator

$(CONFIGURATION_TEMP_DIR) = $()/Build/Intermediates/UtilLib.build/Debug-iphonesimulator

$(TARGET_BUILD_DIR) = $()/Build/Products/Debug-iphonesimulator

$(SDK_NAME) = iphonesimulator5.0

$(PLATFORM_NAME) = iphonesimulator

$(CONFIGURATION) = Debug

$(TARGET_NAME) = UtilLib

$(EXECUTABLE_NAME) = libUtilLib.a 可执行文件名

${IPHONEOS_DEPLOYMENT_TARGET} 5.0

$(ACTION) = build

$(CURRENTCONFIG_SIMULATOR_DIR) 当前模拟器路径

$(CURRENTCONFIG_DEVICE_DIR) 当前设备路径

$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME =

$()/Build/Products/Debug-iphonesimulator

$(PROJECT_TEMP_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) = $()/Build/Intermediates/UtilLib.build/Debug-iphonesimulator

自定义变量

${CONFIGURATION}-iphoneos 表示:Debug-iphoneos

${CONFIGURATION}-iphonesimulator 表示:Debug-iphonesimulator

$(CURRENTCONFIG_DEVICE_DIR) = ${SYMROOT}/${CONFIGURATION}-iphoneos

$(CURRENTCONFIG_SIMULATOR_DIR) = ${SYMROOT}/${CONFIGURATION}-iphonesimulator

自定义一个设备无关的路径(用来存放各种架构arm6/arm7/i386输出的产品)

$(CREATING_UNIVERSAL_DIR) = ${SYMROOT}/${CONFIGURATION}-universal

自定义变量代表的值

$(CURRENTCONFIG_DEVICE_DIR) = $()/Build/Products/Debug-iphoneos

$(CURRENTCONFIG_SIMULATOR_DIR) = $()/Build/Products/Debug-iphonesimulator

$(CREATING_UNIVERSAL_DIR) = $()/Build/Products/Debug-universal

iphoneos5.0下的编译脚本:

xcodebuild -project "UtilLib.xcodeproj" -configuration
"Debug" -target "UtilLib" -sdk "iphoneos5.0" -arch "armv6 armv7" build
RUN_CLANG_STATIC_ANALYZER=NO $(BUILD_DIR)="${BUILD_DIR}"
BUILD_ROOT="${BUILD_ROOT}"

iphonesimulator5.0下的编译脚本:

xcodebuild -project "UtilLib.xcodeproj" -configuration
"Debug" -target "UtilLib" -sdk "iphonesimulator5.0" -arch "i386" build
RUN_CLANG_STATIC_ANALYZER=NO $(BUILD_DIR)="${BUILD_DIR}"
BUILD_ROOT="${BUILD_ROOT}"

加上下面一句表示输出到文件:

> "${BUILD_ROOT}.build_output"

lipo脚本工具:合并iPhone模拟器和真机的静态类库,生成通用库

lipo -create -output
"${CREATING_UNIVERSAL_DIR}/${EXECUTABLE_NAME}"
"${CURRENTCONFIG_DEVICE_DIR}/${EXECUTABLE_NAME}"
"${CURRENTCONFIG_SIMULATOR_DIR}/${EXECUTABLE_NAME}"

意思是:把"${CURRENTCONFIG_DEVICE_DIR}目录下的.a文件,和${CURRENTCONFIG_SIMULATOR_DIR}目录下的.a文件合并,

在${CREATING_UNIVERSAL_DIR}目录下,生成两个设备都通用的静态库,

例如:lipo -create -output xy.a x.a y.a

二、xcode4中build Settings常见参数解析

1.Installation Directory:安装路径

静态库编译时,在Build Settings中Installation Directory设置“$(BUILT_PRODUCTS_DIR)”

Skip Install设为YES

Installation Directory默认为/usr/local/lib

因为Build Location默认时,.a文件会放在很长(比如:/Users/xxx/Library/Developer/Xcode/DerivedData/xxxProgram

dalrvzehhtesxdfqhxixzafvddwe/Build/Products/Debug-iPhoneos)的路径下,或是我们target指定的路径

Skip Install如果是NO,可能会被安装到默认路径/usr/local/lib

2.Public Headers Folder Path:对外公开头文件路径

设为“include”(具体的头文件路径为:$(BUILT_PRODUCTS_DIR)/include/xx.h)

在最终文件.a同级目录下生成一个include目录

默认:/usr/local/include

Public Headers Folder Path这个路径就是使用这lib的某工程需要依赖的外部头文件.导入这路径后,#include/import "xx.h"才能看到

3.User Header Search Paths:依赖的外部头文件搜索路径

设置为“$(BUILT_PRODUCTS_DIR)/include”

和2中路径对应

4.Per-configuration Build Products Path:最终文件路径

比如设为“../app”,就会在工程文件.xcodeproj上一层目录下的app目录里,创建最终文件

默认为$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)

等于$(BUILT_PRODUCTS_DIR)

5.Per-configuration Intermediate Build Files Path:临时中间文件路径

默认为:$(PROJECT_TEMP_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)

6.Code Signing Identity:真机调试的证书选择

选一个和Bundle identifier相对应的证书

Library Search Paths:库搜索路径

Architectures:架构,设为 armv6 或 armv7

Valid Architectures:应用框架,可以设为 armv6、 armv7 或i386

Product Name:工程文件名,默认为$(TARGET_NAME)

Info.plist File:info文件路径

Build Variants:默认为normal

Other Linker Flags:其他链接标签

设为“-ObjC”

当导入的静态库使用了类别,需要设为-ObjC

iOS Deployment Target:ios部署对象

比如可以选择设为,ios3到ios5的一种版本

Prefix Header:预编头文件(比如:UtilLib/UtilLib-Prefix.pch)

Precompile Prefix Header:设为“Yes”,表示允许加入预编译头

三、workspace(工作区)

作用:管理多个工程(project),多工程联编

四、workspace多工程联编设置

一、

1.新建一个静态库工程,比如UtilLib,并生成UtilLib.h和UtilLib.m文件

2.选中需要公开的头文件,

把右侧栏的Target Membership中设置为public

或则,选中工程目录target的Build Phases标签的copy headers项,在public中添加要公开的头文件

3.Architectures设为:armv6 armv7

4.Valid Architectures设为:armv6 armv7 i386

5.Build Products Path设为:$(SRCROOT)/../build

6.Per-configuration Build Products Path设为:

$(SRCROOT)/../build/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)

7.Per-configuration Intermediate Build Files Path设为:

$(SRCROOT)/../build/$(TARGET_NAME).build/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)

8.设置安装路径:Installation Directory项

9.设置对外公开的头文件路径:Public Headers Folder Path项

10.为静态库添加依赖的shell脚本

选中工程目录target的Build Phases标签,点击由下角的Add Build Phase按钮

在弹出的菜单里选择Add run script项,然后页面中会多出一个Run Script项

在黑框里填写"$SRCROOT/mergeArmSymbols.sh"

建立对此脚本的依赖(编译静态库的后会运行此脚本)

如果编译时设备选的是iphone simulator:

则此脚本会在对应iphone device的产品目录Debug-iphoneos中,生成对device有用的.a静态库,

相反,如果设备选的是iphone device:

则此脚本会在对应iphone simulator的产品目录Debug-iphoneos中,生成对simulator有用的.a静态库

最后,此脚本调用lipo工具,把本工程生成静态库与此脚本生成的静态库合并,生成simulator和device都通用的.a文件

11.具体bash shell脚本如下:

[plain] view plaincopy

    1. mergeArmSymbols.sh
    2. # Version 2.0 (updated for Xcode 4, with some fixes)
    3. # Author: Adam Martin - http://twitter.com/redglassesapps
    4. # Based on: original script from Eonil (main changes: Eonil‘s script WILL NOT WORK in Xcode GUI - it WILL CRASH YOUR COMPUTER)
    5. #
    6. # More info: see this Stack Overflow question:
      http://stackoverflow.com/questions/3520977/build-fat-static-library-device-simulator-using-xcode-and-sdk-4
    7. #################[ Tests: helps workaround any future bugs in Xcode ]########
    8. #
    9. DEBUG_THIS_SCRIPT="true"
    10. if [ $DEBUG_THIS_SCRIPT = "true" ]
    11. then
    12. echo "########### TESTS #############"
    13. echo "Use the following variables when debugging this script; note that they may change on recursions"
    14. echo "BUILD_DIR = $BUILD_DIR"
    15. echo "BUILD_ROOT = $BUILD_ROOT"
    16. echo "CONFIGURATION_BUILD_DIR = $CONFIGURATION_BUILD_DIR"
    17. echo "BUILT_PRODUCTS_DIR = $BUILT_PRODUCTS_DIR"
    18. echo "CONFIGURATION_TEMP_DIR = $CONFIGURATION_TEMP_DIR"
    19. echo "TARGET_BUILD_DIR = $TARGET_BUILD_DIR"
    20. echo "SDK_NAME = $SDK_NAME"
    21. echo "PLATFORM_NAME = $PLATFORM_NAME"
    22. echo "CONFIGURATION = $CONFIGURATION"
    23. echo "TARGET_NAME = $TARGET_NAME"
    24. echo "ARCH_TO_BUILD = $ARCH_TO_BUILD"
    25. echo "ARCH_TO_BUILD = $ARCH_TO_BUILD"
    26. echo "ACTION = $ACTION"
    27. echo "SYMROOT = $SYMROOT"
    28. echo "EXECUTABLE_NAME = $EXECUTABLE_NAME"
    29. echo "CURRENTCONFIG_SIMULATOR_DIR = $CURRENTCONFIG_SIMULATOR_DIR"
    30. echo "CURRENTCONFIG_DEVICE_DIR = $CURRENTCONFIG_DEVICE_DIR"
    31. echo "#############Other###########"
    32. echo "BUILD_DIR/CONFIGURATION/EFFECTIVE_PLATFORM_NAME = $BUILD_DIR/$CONFIGURATION$EFFECTIVE_PLATFORM_NAME"
    33. echo "PROJECT_TEMP_DIR/CONFIGURATION/EFFECTIVE_PLATFORM_NAME = $PROJECT_TEMP_DIR/$CONFIGURATION$EFFECTIVE_PLATFORM_NAME"
    34. fi
    35. #####################[ part 1 ]##################
    36. # First, work out the BASESDK version number
    37. # (incidental: searching for substrings in sh is a nightmare! Sob)
    38. SDK_VERSION=$(echo ${SDK_NAME} | grep -o ‘.\{3\}$‘)
    39. # Next, work out if we‘re in SIM or DEVICE
    40. if [ ${PLATFORM_NAME} = "iphonesimulator" ]
    41. then
    42. OTHER_SDK_TO_BUILD=iphoneos${SDK_VERSION}
    43. ARCH_TO_BUILD="armv6 armv7"
    44. else
    45. OTHER_SDK_TO_BUILD=iphonesimulator${SDK_VERSION}
    46. ARCH_TO_BUILD="i386"
    47. fi
    48. echo "XCode has selected SDK: ${PLATFORM_NAME} with
      version: ${SDK_VERSION} (although back-targetting:
      ${IPHONEOS_DEPLOYMENT_TARGET})"
    49. echo "...therefore, OTHER_SDK_TO_BUILD = ${OTHER_SDK_TO_BUILD}"
    50. #
    51. #####################[ end of part 1 ]##################
    52. #####################[ part 2 ]##################
    53. #
    54. # IF this is the original invocation, invoke whatever other builds are required
    55. #
    56. # Xcode is already building ONE target... build ONLY the missing platforms/configurations.
    57. if [ "true" == ${ALREADYINVOKED:-false} ]
    58. then
    59. echo "RECURSION: Not the root invocation, don‘t recurse"
    60. else
    61. # Prevent recursion
    62. export ALREADYINVOKED="true"
    63. echo "RECURSION: I am the root... recursing all missing build targets..."
    64. echo "RECURSION: ...about to invoke: xcodebuild -configuration
      \"${CONFIGURATION}\" -target \"${TARGET_NAME}\" -sdk
      \"${OTHER_SDK_TO_BUILD}\" -arch \"${ARCH_TO_BUILD}\" ${ACTION}
      RUN_CLANG_STATIC_ANALYZER=NO"
    65. xcodebuild -project "${TARGET_NAME}.xcodeproj"
      -configuration "${CONFIGURATION}" -target "${TARGET_NAME}" -sdk
      "${OTHER_SDK_TO_BUILD}" -arch "${ARCH_TO_BUILD}" ${ACTION}
      RUN_CLANG_STATIC_ANALYZER=NO BUILD_DIR="${BUILD_DIR}"
      BUILD_ROOT="${BUILD_ROOT}" > "${BUILD_ROOT}.build_output"
    66. ACTION="build"
    67. # Merge all platform binaries as a fat binary for each configurations.
    68. # Calculate where the (multiple) built files are coming from:
    69. CURRENTCONFIG_DEVICE_DIR=${SRCROOT}/../build/${CONFIGURATION}-iphoneos
    70. CURRENTCONFIG_SIMULATOR_DIR=${SRCROOT}/../build/${CONFIGURATION}-iphonesimulator
    71. echo "Taking device build from: ${CURRENTCONFIG_DEVICE_DIR}"
    72. echo "Taking simulator build from: ${CURRENTCONFIG_SIMULATOR_DIR}"
    73. CREATING_UNIVERSAL_DIR=${SRCROOT}/../build/${CONFIGURATION}-universal
    74. echo "...outputing a universal arm6/arm7/i386 build to: ${CREATING_UNIVERSAL_DIR}"
    75. # ... remove the products of previous runs of this script
    76. # NB: this directory is only created by this script - it should be safe to delete
    77. rm -rf "${CREATING_UNIVERSAL_DIR}"
    78. mkdir "${CREATING_UNIVERSAL_DIR}"
    79. #
    80. echo "lipo: for current configuration (${CONFIGURATION}) creating output file: ${CREATING_UNIVERSAL_DIR}/${EXECUTABLE_NAME}"
    81. lipo -create -output "${CREATING_UNIVERSAL_DIR}/${EXECUTABLE_NAME}"
      "${CURRENTCONFIG_DEVICE_DIR}/${EXECUTABLE_NAME}"
      "${CURRENTCONFIG_SIMULATOR_DIR}/${EXECUTABLE_NAME}"
    82. #######custom########
    83. #copy universal lib to ../libs
    84. libsDir=../libs
    85. includeDir=../include
    86. rm -rf "${libsDir}"
    87. mkdir -p "${libsDir}"
    88. echo "cp -R ${CREATING_UNIVERSAL_DIR}/${EXECUTABLE_NAME} ${libsDir}"
    89. cp -R "${CREATING_UNIVERSAL_DIR}/${EXECUTABLE_NAME}" "${libsDir}"
    90. echo "cp -R ${CURRENTCONFIG_DEVICE_DIR}/include ${includeDir}"
    91. cp -R "${CURRENTCONFIG_DEVICE_DIR}/include" "${includeDir}"
    92. fi

      下载右边的图片,然后把后缀改为.sh(其实就是上面的脚本,因为博客园只能上传图片)

      静态库编译后的目录结构如下:

      二、

      1.新建主工程,比如Nuno,添加对静态库的依赖

      点击工程,在Build Phases标签的Link Binary With Libraries项中点击加号添加UtilLib.a库

      选中上面的红色项,在右边栏的Location选Relative to Project,把值设为../libs/libUtilLib.a

      2.设置主工程依赖的外部头文件路径:User Header Search Paths项

      $(SRCROOT)/../include

      3.设置Header Search Paths为:$(SRCROOT)/../include

      4.设置Library Search Paths为:$(SRCROOT)/../libs

      编译运行即可实现联编

      (备注:选择模拟器iphone 5.0 simulator,编译静态库的时,最终文件会在Debug-iphonesimulator,就算成功.a文件还是红色,

      这是可能是xcode的bug,不会自动切换路径

      因为$(BUILT_PRODUCTS_DIR)所指的位置,是build/Debug-iphonesos,不是包含最终.a文件的Debug-iphonesimulator;

      选择ios Device,编译成的最终文件才在build/Debug-iphonesos下,.a文件变成非红色

      所有得用mergeArmSymbols.sh脚本来解决)

时间: 2024-09-15 04:47:01

xcode 路径的相关文章

XCode Cocoapod错误

Could not automatically select an Xcode project. Specify one in your Podfile like so 原文http://blog.csdn.net/kolnick/article/details/38954325 lhdeiMac:AnimatedSteeringDemo lh$ pod install Analyzing dependencies [!] Could not automatically select an Xc

SimPholders2 模拟器 App 文件路径查看工具

SimPholder2.app 官网下载地址:http://www.simpholders.com ?当使用 Xcode beta 版本切换到 Xcode 正式版本时,点击 SimPholders2.app 安装,提示 “Xcode is not installed” ,原因是 app 安装时去验证 Xcode 路径下是否存在,这里由于安装的是 Xcode.app,所以路径应该更改:打开 shell 终端,输入如下命令: 1 sudo /usr/bin/xcode-select -switch

重要信息:::::Xcode 8 不支持第三方插件

幽灵入侵,完整的XCodeGhost 事件到底是什么样的? 2015-09-21 10:08 腾讯安全平台部 9条评论 [编者按]本文来自腾讯安全应急中心,作者Gmxp. 前言 这几天安全圈几乎被XCodeGhost事件刷屏,大家都非常关注,各安全团队都很给力,纷纷从不同角度分析了病毒行为.传播方式.影响面积甚至还人肉到了作者信息.拜读了所有网上公开或者半公开的分析报告后,我们认为,这还不是全部,所以我们来补充下完整的XCodeGhost事件. 由于行文仓促,难免有诸多错漏之处,还望同行批评指正

安装 xcode 5.1.1

https://developer.apple.com/downloads/ 切换路径xcode 路径.然并卵,不好用 http://cms.35g.tw/coding/xcode-select-%E5%88%87%E6%8F%9Bxcode%E9%A0%90%E8%A8%AD%E8%B7%AF%E5%BE%91/ http://johnjardin.ukuvuma.co.za/2014/10/01/appcelerator-tip-switch-ios-sdks-mobile-app-deve

Xcode多版本切换

查看当前默认XCode路径 xcode-select --print-path 切换默认XCode路径 sudo xcode-select -switch 需要切换的XCode.app的路径

终端:Xcode模拟器上安装.app方法

有的时候,我们可能需要将别人的Xcode运行之后的程序包(xxx.app)安装在自己的模拟器上,如下我将介绍如何通过终端来安装. 实现 获取自己Xcode生成的xxx.app steps 1:在工程didFinishLaunchingWithOptions:方法中打印bundle路径: NSLog(@"%@", [[NSBundlemainBundle] pathForAuxiliaryExecutable:@""]); steps 2:拷贝打印的bundle路径,

MAC OSX Xcode硬盘清理

1.移除对旧设备的支持影响:可重新生成:再连接旧设备调试时,会重新自动生成.我移除了4.3.2, 5.0, 5.1等版本的设备支持.路径:~/Library/Developer/Xcode/iOS DeviceSupport 2.移除旧版本的模拟器支持影响:不可恢复:如果需要旧版本的模拟器,就需要重新下载了.我移除了4.3.2, 5.0, 5.1等旧版本的模拟器.路径:~/Library/Application Support/iPhone Simulator 新版xcode路径:~/Libra

xCode中如何安装旧的模拟器

http://blog.csdn.net/cmengzhongren/article/details/50414493 这里给出如何把老版本的SDK加入到新的Xcode中的方法.其实很简单,就是将老版本的sdk拷贝过去. 打开老的Xcode安装路径(你可以去 Apple Dev Center 下载老版本的Xcode dmg包,解压出来对应的SDK包.):Applications/Xcode.app/Contents/Developer/Platforms /iPhoneOS.platform/D

Xcode Ghost

Xcode Ghost,是一种手机病毒,主要通过非官方下载的 Xcode 传播,能够在开发过程中通过 CoreService 库文件进行感染,使编译出的 App 被注入第三方的代码,向指定网站上传用户数据.也就是说,开发者下载的非官方途径的Xcode带有XcodeGhost 病毒. XcodeGhost 病毒目前会上传产品自身的部分基本信息(安装时间,应用ID,应用名称,系统版本,语言,国家)等,不会涉及到个人信息.另外,感染制作者的服务器已关闭,已经不构成实质上的信息泄露. 我们发现开发人员使