views:

640

answers:

2

I've set LIBRARY_SEARCH_PATHS to /opt/local/lib, and verified that the library in question is there (I'm linking to GLEW):

$ls /opt/local/lib

libGLEW.1.5.1.dylib libfreetype.a  libz.a
libGLEW.1.5.dylib   libfreetype.dylib libz.dylib
libGLEW.a    libfreetype.la  pkgconfig
libGLEW.dylib    libz.1.2.3.dylib
libfreetype.6.dylib libz.1.dylib

but Xcode gives me the linker error

library not found for -lGLEW

I'm generating the Xcode project with CMake, so I don't want to explicitly modify the Xcode project (if someone suggests adding it as a framework, or something like that). Xcode recognizes USER_HEADER_SEARCH_PATHS fine (as in this question); why doesn't it work here?

+1  A: 

Xcode works on potentially multiple SDK's, so whenever your define these kinds of things (like HEADER_SEARCH_PATHS or LIBRARY_SEARCH_PATHS) the current SDK root is prepended to the actual path that's getting passed to the linker.

So, one way to make this work would be to add your directory to the SDK. For example, assuming you're building with the Mac OS X 10.5 sdk, you could add your opt dir:

ln -s /opt /Developer/SDKs/MacOSX10.5.sdk/opt

Your library would now be found on your system.

If you don't want to do this, then you will have to look at CMake and find out how to get it to generate a library requirement for your actual library (I don't know anything about CMake, so I can't help you there). This is also why you see a difference between USER_HEADER_SEARCH_PATHS and HEADER_SEARCH_PATHS re your other question.

As another option, you could also specify this path with the OTHER_LDFLAGS build variable:

OTHER_LDFLAGS=-L/opt/local/lib

This would cause the linker to search /opt/local/lib as well as its standard paths and wouldn't require you to generate a different project file.

Jason Coco
A: 

Perhaps adding something like this to your CMakeLists.txt?

find_library(GLEW_LIB GLEW /opt/local/lib)
if(NOT ${GLEW_LIB})
  message(FATAL_ERROR "Could not find GLEW")
endif()
target_link_libraries(myprogram ${GLEW_LIB} ...)

Where myprogram is the name of the target executable that needs to link with the library. You would replace the ... with the other libraries you are using on that executable.

This way CMake would handle the library path details for you.

rq