Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make /usr/local/lib a default library search path for ld on mac os x?

I have XCode installed, but for some reason, /usr/local/lib is not amongst the default library 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 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?

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.

Was there an option about this when installing XCode? (it's a work computer, haven't installed it myself)

like image 754
armando.sano Avatar asked Sep 29 '22 07:09

armando.sano


1 Answers

To add a temporary library to my project using Xcode I did the following:

enter image description here

To add a temporary include path to my XCode library search paths I had to do the following:

enter image description here

If you want to add default include and search paths you 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:

/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.

like image 107
Francisco Aguilera Avatar answered Oct 03 '22 06:10

Francisco Aguilera