I'd like to add ~/include to my include path for all projects while using Xcode, something like setting the environment variable CPLUS_INCLUDE_PATH
in Linux. (See here for the related Linux question.)
我想在使用Xcode时为所有项目添加〜/ include到我的包含路径,就像在Linux中设置环境变量CPLUS_INCLUDE_PATH一样。 (有关相关的Linux问题,请参阅此处。)
Is this possible in Xcode? I tried setting the above environment variable, but it doesn't seem to work. (And if it is possible, I'd like to also set related paths, like LIBRARY_PATH and LD_LIBRARY_PATH.)
这在Xcode中是否可行?我尝试设置上面的环境变量,但它似乎不起作用。 (如果可能的话,我还想设置相关的路径,比如LIBRARY_PATH和LD_LIBRARY_PATH。)
5 个解决方案
#1
According to Apple's Docs, you are able to provide a default for any build setting using an environment variable.
根据Apple的Docs,您可以使用环境变量为任何构建设置提供默认值。
In this case, you'd want to set HEADER_SEARCH_PATHS
. For some reason I don't understand, this doesn't work. It works fine for other build settings (for example, OTHER_CFLAGS), but not for HEADER_SEARCH_PATHS
. You can see what the variable name for any setting is by opening the research assistant in the build settings window (book button on the bottom left.)
在这种情况下,您需要设置HEADER_SEARCH_PATHS。由于某些原因我不明白,这不起作用。它适用于其他构建设置(例如,OTHER_CFLAGS),但不适用于HEADER_SEARCH_PATHS。您可以通过在构建设置窗口中打开研究助手(左下方的书籍按钮)来查看任何设置的变量名称。
One var that does work is USER_HEADER_SEARCH_PATHS
, which is just like what you want, but only works for paths in double quotes (not in angle brackets.)
一个可行的var是USER_HEADER_SEARCH_PATHS,它就像你想要的那样,但只适用于双引号中的路径(不在尖括号中)。
So
#include "bar.h"
would work, but
会工作,但是
#include <bar.h>
wouldn't.
The build settings plist referenced from the above article on environment variables should end up looking something like this:
从上面关于环境变量的文章中引用的构建设置plist最终应该看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>USER_HEADER_SEARCH_PATHS</key>
<string>~/test</string>
</dict>
</plist>
Hope that helps.
希望有所帮助。
#2
For any of you blessed darlings that are trying to achieve this, or any other hack of ~/.MacOSX/environment.plist
, aka global environmental variables in this post-Mountain-Lion world, check out EnvPane - An OS X preference pane for environment variables
对于任何想要实现这一目标的祝福宠儿,或者任何其他ha~~MacOSX / environment.plist,也就是后山地狮子世界中的全球环境变量,请查看EnvPane - OS X偏好窗格环境变量
EnvPane is a preference pane for Mac OS X 10.8 (Mountain Lion) that lets you set environment variables for all programs in both graphical and terminal sessions. Not only does it restore support for ~/.MacOSX/environment.plist in Mountain Lion, it also publishes your changes to the environment immediately, without the need to log out and back in. This works even for changes made by manually editing ~/.MacOSX/environment.plist, not just changes made via the preference pane.
EnvPane是Mac OS X 10.8(Mountain Lion)的首选项窗格,可让您为图形和终端会话中的所有程序设置环境变量。它不仅可以恢复对Mountain Lion中〜/ .MacOSX / environment.plist的支持,还可以立即发布您对环境的更改,而无需注销和重新登录。这甚至适用于手动编辑所做的更改〜/ .MacOSX / environment.plist,而不仅仅是通过首选项窗格进行的更改。
#3
Add the HEADER_SEARCH_PATHS
build setting to your Xcode project. This setting takes a space separated list of paths and if the path ends in a double star (**
), it will search subdirectories recursively. So to answer for your example, set HEADER_SEARCH_PATHS
to:
将HEADER_SEARCH_PATHS构建设置添加到Xcode项目中。此设置采用空格分隔的路径列表,如果路径以双星(**)结尾,则将以递归方式搜索子目录。因此,要回答您的示例,请将HEADER_SEARCH_PATHS设置为:
~/include
If you had a number of paths to include, you would set it to something like:
如果要包含多个路径,则应将其设置为:
~/include ~/my_other_includes/** /usr/local/special_frameworks/**
#4
Just select a .c or .m file in your "Groups & Files Tab" and choose "get Info" through RMB, then under "build" you can add additional Compiler Flags like -I for additional include searchpath.
只需在“Groups&Files”选项卡中选择一个.c或.m文件,然后通过RMB选择“获取信息”,然后在“build”下,您可以添加额外的编译器标志,如-I,用于其他包括searchpath。
#5
Build settings are not environment variables, and environment variables are not build settings. Setting an environment variable will not affect Xcode builds.
构建设置不是环境变量,环境变量不是构建设置。设置环境变量不会影响Xcode构建。
USER_HEADER_SEARCH_PATHS
is a build setting, and putting a list of paths into it will achieve what you want. If you set the value in a target's inspector, it will take effect for only that target (and only for the Build Configurations you designate). If you set it in the Project inspector, it will take effect in all targets in the project, unless a target overrides it with its own setting.
USER_HEADER_SEARCH_PATHS是一个构建设置,将路径列表放入其中将实现您的目标。如果在目标的检查器中设置该值,它将仅对该目标生效(并且仅对您指定的构建配置生效)。如果在项目检查器中设置它,它将在项目中的所有目标中生效,除非目标使用自己的设置覆盖它。
For paths that are specific to your machine, you should probably define a Source Tree in the Xcode Preferences, such as LOCAL_INCLUDE = ~/include
. Then define USER_HEADER_SEARCH_PATHS = $(LOCAL_INCLUDE)
in the project. This way, other people can open your project and build it by setting their Source Tree to the particular location of the local includes on their machine, without having to change the project file.
对于特定于您的计算机的路径,您应该在Xcode首选项中定义源树,例如LOCAL_INCLUDE =〜/ include。然后在项目中定义USER_HEADER_SEARCH_PATHS = $(LOCAL_INCLUDE)。这样,其他人可以打开您的项目并通过将其源树设置到其计算机上本地包含的特定位置来构建它,而无需更改项目文件。
#1
According to Apple's Docs, you are able to provide a default for any build setting using an environment variable.
根据Apple的Docs,您可以使用环境变量为任何构建设置提供默认值。
In this case, you'd want to set HEADER_SEARCH_PATHS
. For some reason I don't understand, this doesn't work. It works fine for other build settings (for example, OTHER_CFLAGS), but not for HEADER_SEARCH_PATHS
. You can see what the variable name for any setting is by opening the research assistant in the build settings window (book button on the bottom left.)
在这种情况下,您需要设置HEADER_SEARCH_PATHS。由于某些原因我不明白,这不起作用。它适用于其他构建设置(例如,OTHER_CFLAGS),但不适用于HEADER_SEARCH_PATHS。您可以通过在构建设置窗口中打开研究助手(左下方的书籍按钮)来查看任何设置的变量名称。
One var that does work is USER_HEADER_SEARCH_PATHS
, which is just like what you want, but only works for paths in double quotes (not in angle brackets.)
一个可行的var是USER_HEADER_SEARCH_PATHS,它就像你想要的那样,但只适用于双引号中的路径(不在尖括号中)。
So
#include "bar.h"
would work, but
会工作,但是
#include <bar.h>
wouldn't.
The build settings plist referenced from the above article on environment variables should end up looking something like this:
从上面关于环境变量的文章中引用的构建设置plist最终应该看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>USER_HEADER_SEARCH_PATHS</key>
<string>~/test</string>
</dict>
</plist>
Hope that helps.
希望有所帮助。
#2
For any of you blessed darlings that are trying to achieve this, or any other hack of ~/.MacOSX/environment.plist
, aka global environmental variables in this post-Mountain-Lion world, check out EnvPane - An OS X preference pane for environment variables
对于任何想要实现这一目标的祝福宠儿,或者任何其他ha~~MacOSX / environment.plist,也就是后山地狮子世界中的全球环境变量,请查看EnvPane - OS X偏好窗格环境变量
EnvPane is a preference pane for Mac OS X 10.8 (Mountain Lion) that lets you set environment variables for all programs in both graphical and terminal sessions. Not only does it restore support for ~/.MacOSX/environment.plist in Mountain Lion, it also publishes your changes to the environment immediately, without the need to log out and back in. This works even for changes made by manually editing ~/.MacOSX/environment.plist, not just changes made via the preference pane.
EnvPane是Mac OS X 10.8(Mountain Lion)的首选项窗格,可让您为图形和终端会话中的所有程序设置环境变量。它不仅可以恢复对Mountain Lion中〜/ .MacOSX / environment.plist的支持,还可以立即发布您对环境的更改,而无需注销和重新登录。这甚至适用于手动编辑所做的更改〜/ .MacOSX / environment.plist,而不仅仅是通过首选项窗格进行的更改。
#3
Add the HEADER_SEARCH_PATHS
build setting to your Xcode project. This setting takes a space separated list of paths and if the path ends in a double star (**
), it will search subdirectories recursively. So to answer for your example, set HEADER_SEARCH_PATHS
to:
将HEADER_SEARCH_PATHS构建设置添加到Xcode项目中。此设置采用空格分隔的路径列表,如果路径以双星(**)结尾,则将以递归方式搜索子目录。因此,要回答您的示例,请将HEADER_SEARCH_PATHS设置为:
~/include
If you had a number of paths to include, you would set it to something like:
如果要包含多个路径,则应将其设置为:
~/include ~/my_other_includes/** /usr/local/special_frameworks/**
#4
Just select a .c or .m file in your "Groups & Files Tab" and choose "get Info" through RMB, then under "build" you can add additional Compiler Flags like -I for additional include searchpath.
只需在“Groups&Files”选项卡中选择一个.c或.m文件,然后通过RMB选择“获取信息”,然后在“build”下,您可以添加额外的编译器标志,如-I,用于其他包括searchpath。
#5
Build settings are not environment variables, and environment variables are not build settings. Setting an environment variable will not affect Xcode builds.
构建设置不是环境变量,环境变量不是构建设置。设置环境变量不会影响Xcode构建。
USER_HEADER_SEARCH_PATHS
is a build setting, and putting a list of paths into it will achieve what you want. If you set the value in a target's inspector, it will take effect for only that target (and only for the Build Configurations you designate). If you set it in the Project inspector, it will take effect in all targets in the project, unless a target overrides it with its own setting.
USER_HEADER_SEARCH_PATHS是一个构建设置,将路径列表放入其中将实现您的目标。如果在目标的检查器中设置该值,它将仅对该目标生效(并且仅对您指定的构建配置生效)。如果在项目检查器中设置它,它将在项目中的所有目标中生效,除非目标使用自己的设置覆盖它。
For paths that are specific to your machine, you should probably define a Source Tree in the Xcode Preferences, such as LOCAL_INCLUDE = ~/include
. Then define USER_HEADER_SEARCH_PATHS = $(LOCAL_INCLUDE)
in the project. This way, other people can open your project and build it by setting their Source Tree to the particular location of the local includes on their machine, without having to change the project file.
对于特定于您的计算机的路径,您应该在Xcode首选项中定义源树,例如LOCAL_INCLUDE =〜/ include。然后在项目中定义USER_HEADER_SEARCH_PATHS = $(LOCAL_INCLUDE)。这样,其他人可以打开您的项目并通过将其源树设置到其计算机上本地包含的特定位置来构建它,而无需更改项目文件。