Why doesn't Xcode recognize my LIBRARY_SEARCH_PATHS?

I set LIBRARY_SEARCH_PATHS to /opt/local/lib and confirmed that the library in question is there (I am bound 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 a linker error

 library not found for -lGLEW 

I am creating an Xcode project using CMake, so I do not 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 he work here?

+4
source share
2 answers

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 to be associated with the library. You would replace ... with other libraries that you use in this executable.

This way CMake will handle the details of the library path.

+2
source

Xcode works with potentially multiple SDKs, so whenever you define these things (e.g. HEADER_SEARCH_PATHS or LIBRARY_SEARCH_PATHS), the current SDK root is added to the actual path that is passed to the linker.

So, one way to make this work would be to add your directory to the SDK. For example, assuming you are building using Mac OS X 10.5 sdk, you can add your option:

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

Your library will now be found on your system.

If you don't want to do this, you will have to take a look at CMake and find out how to get it to generate library requirements for your real library (I don't know anything about CMake, so I can't help you there). That's why you see the difference between USER_HEADER_SEARCH_PATHS and HEADER_SEARCH_PATHS your other question.

As another option, you can also specify this path with the assembly variable OTHER_LDFLAGS:

 OTHER_LDFLAGS=-L/opt/local/lib 

This will cause the linker to look for / opt / local / lib as well as its standard paths and not require you to create another project file.

+1
source

All Articles