Xcode dylib searches in / usr / lib

I created dylib in Xcode. I installed the installation directory in @rpath. Then I created a test project in which I use this dylib. When I run it, I get a dyld error: library not loaded .... Reason: image not found.

BUT ... if I put this dylib in the / usr / lib folder, then it works like a charm.

So my question is, is there a way when compiling this dylib, can I specify some settings so that it does not look in / usr / lib and just looks where it is (if that makes sense)? Thanks!

+2
source share
1 answer

Edit: I am re-reading your question after writing this answer. Since you are creating only dylib and not an executable, you need to use the install_name_tool -id . I do not believe that you can say that he seek himself where he was. I think you should give it a way. In this example, it is examined in the path of the application package, which is a pretty reasonable place to search.


You need to change the path in which your application searches for the file and the path that the library expects to find. Here is an example where I use three OpenCV libraries.

These first lines tell the application to look for libraries in the Frameworks folder of the application package. ( $BUILT_PRODUCTS_DIR/$EXECUTABLE_PATH is a combination of environment variables that define the executable.)

 #Fix references in executable install_name_tool -change lib/libopencv_core.2.3.dylib @executable_path/../Frameworks/libopencv_core.2.3.1.dylib $BUILT_PRODUCTS_DIR/$EXECUTABLE_PATH install_name_tool -change lib/libopencv_imgproc.2.3.dylib @executable_path/../Frameworks/libopencv_imgproc.2.3.1.dylib $BUILT_PRODUCTS_DIR/$EXECUTABLE_PATH install_name_tool -change lib/libopencv_highgui.2.3.dylib @executable_path/../Frameworks/libopencv_highgui.2.3.1.dylib $BUILT_PRODUCTS_DIR/$EXECUTABLE_PATH 

I got the first parameter ( lib/libopencv_core.2.3.dylib ) by previously running otool -L .

 $ otool -L libopencv_imgproc.2.3.1.dylib libopencv_imgproc.2.3.1.dylib: lib/libopencv_imgproc.2.3.dylib (compatibility version 2.3.0, current version 2.3.1) lib/libopencv_core.2.3.dylib (compatibility version 2.3.0, current version 2.3.1) /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3) /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.11) 

These next lines tell libraries to look for themselves in the Frameworks folder.

 #Fix install location in libraries install_name_tool -id @executable_path/../Frameworks/libopencv_core.2.3.1.dylib $BUILT_PRODUCTS_DIR/$FRAMEWORKS_FOLDER_PATH/libopencv_core.2.3.1.dylib install_name_tool -id @executable_path/../Frameworks/libopencv_imgproc.2.3.1.dylib $BUILT_PRODUCTS_DIR/$FRAMEWORKS_FOLDER_PATH/libopencv_imgproc.2.3.1.dylib install_name_tool -id @executable_path/../Frameworks/libopencv_highgui.2.3.1.dylib $BUILT_PRODUCTS_DIR/$FRAMEWORKS_FOLDER_PATH/libopencv_highgui.2.3.1.dylib 

And these lines tell the libraries to look for each other in the Frameworks folder.

 #Fix references in libraries install_name_tool -change lib/libopencv_core.2.3.dylib @executable_path/../Frameworks/libopencv_core.2.3.1.dylib $BUILT_PRODUCTS_DIR/$FRAMEWORKS_FOLDER_PATH/libopencv_imgproc.2.3.1.dylib install_name_tool -change lib/libopencv_core.2.3.dylib @executable_path/../Frameworks/libopencv_core.2.3.1.dylib $BUILT_PRODUCTS_DIR/$FRAMEWORKS_FOLDER_PATH/libopencv_highgui.2.3.1.dylib install_name_tool -change lib/libopencv_imgproc.2.3.dylib @executable_path/../Frameworks/libopencv_imgproc.2.3.1.dylib $BUILT_PRODUCTS_DIR/$FRAMEWORKS_FOLDER_PATH/libopencv_highgui.2.3.1.dylib 

All of this came from my target stage of running Script in my Xcode project.

+5
source

Source: https://habr.com/ru/post/907407/


All Articles