xcode 使/usr/local/lib 成为mac os x 上ld 的默认库搜索路径?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27314733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Make /usr/local/lib a default library search path for ld on mac os x?
提问by armando.sano
I have XCode installed, but for some reason, /usr/local/lib is not amongst the default library search paths:
我安装了 XCode,但由于某种原因,/usr/local/lib 不在默认库搜索路径中:
gcc -Xlinker -v
gives me:
给我:
@(#)PROGRAM:ld PROJECT:ld64-224.1
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 armv6m armv7m armv7em
Library search paths:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib
Framework search paths:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/
This is unfortunate since /usr/local/lib
is a fairly canonical location for installed libraries and and there is no /etc/ld.so.conf
+ldconfig
on mac os x
to modify the default library search paths. So without using -L/usr/local/lib
this results in a linker error. Is there any other, non-runtime option than setting the environment variable DYLD_LIBRARY_PATH
?
这是不幸的,因为它/usr/local/lib
是已安装库的相当规范的位置,并且没有/etc/ld.so.conf
+ ldconfig
onmac os x
来修改默认库搜索路径。所以不使用-L/usr/local/lib
它会导致链接器错误。除了设置环境变量之外,还有其他非运行时选项DYLD_LIBRARY_PATH
吗?
EDIT: Setting the DYLD_LIBRARY_PATH
env variable did nothing for me. I had to set the LIBRARY_PATH
env variable instead to be able to link libraries installed under /usr/local/lib
with gcc
.
编辑:设置DYLD_LIBRARY_PATH
env 变量对我没有任何作用。我必须设置LIBRARY_PATH
环境变量,而不是要能下安装链接库/usr/local/lib
用gcc
。
Was there an option about this when installing XCode
? (it's a work computer, haven't installed it myself)
安装时有没有关于这个的选项XCode
?(是工作电脑,自己没装过)
回答by Francisco Aguilera
To add a temporary library to my project using Xcode I did the following:
要使用 Xcode 向我的项目添加临时库,我执行了以下操作:
To add a temporary include path to my XCode library search paths I had to do the following:
要将临时包含路径添加到我的 XCode 库搜索路径,我必须执行以下操作:
If you want to add default include and search pathsyou need to use:
如果要添加默认包含和搜索路径,则需要使用:
For include paths:
对于包含路径:
CPATH
C_INCLUDE_PATH
CPLUS_INCLUDE_PATH
OBJC_INCLUDE_PATH
And for library paths:
对于库路径:
LIBRARY_PATH
In order for Xcode and other GUI applications in OS X (tested on 10.10) to be able to access these environment variables, you need to set variables using:
为了让 OS X 中的 Xcode 和其他 GUI 应用程序(在 10.10 上测试)能够访问这些环境变量,您需要使用以下方法设置变量:
/bin/launchctl setenv LIBRARY_PATH /usr/local/lib
/bin/launchctl setenv CPATH /usr/local/include
But these are not permanent. In order to have these variables across restarts, you need to create a startup script. See this page for an example.
但这些都不是永久性的。为了在重新启动时使用这些变量,您需要创建一个启动脚本。有关示例,请参阅此页面。