Make / usr / local / lib the default library search path for ld on mac os x?
I have XCode installed, but for some reason / usr / local / lib is not included in the default search paths:
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 as it /usr/local/lib
is a pretty canonical place for installed libraries, and there is no /etc/ld.so.conf
+ ldconfig
on mac os x
to change the default search paths in a library. So without using -L/usr/local/lib
it results in a linker error. Is there any other no-run option than setting an environment variable 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 the libraries installed in /usr/local/lib
with gcc
.
Was it possible to set this parameter during installation XCode
? (this is a working computer, didn't install it myself)
source to share
To add a temporary library to my project using Xcode, I did the following:
To add a temporary include path to my Xcode library search path, I had to do the following:
If you want to add default include and find paths you need to use:
For included paths:
CPATH
C_INCLUDE_PATH
CPLUS_INCLUDE_PATH
OBJC_INCLUDE_PATH
And for the paths to the library:
LIBRARY_PATH
In order for Xcode and other GUI applications on OS X (tested 10.10) to have access to these environment variables, you need to set the variables using:
/bin/launchctl setenv LIBRARY_PATH /usr/local/lib
/bin/launchctl setenv CPATH /usr/local/include
But they are not permanent. In order for these variables to be restarted, you need to create a startup script. See this page for an example.
source to share