How can I get Xcode to link and debug an application using the Boost Filesystem?

TL DR

The Objective-C application is linked to the static library that dynamic links Boost Filesystem. An application can be launched from the output directory using the terminal, but trying to start from the Xcode or Finder debugger gives the error dyld: Library not loaded: libboost_filesystem.dylib <snip> Reason: image not found .

Problem

In my Xcode project, I have a structure that looks like this:

 MainProject (Objective-C) - static_lib_that_uses_filesystem (C++) 

To get everything connected, I added libboost_system and libboost_filesystem dylibs to the build phase of Link Binary with Libraries in MainProject.

When I try to run the application from Xcode or Finder, I get:

 sharedlibrary apply-load-rules all warning: Unable to read symbols for libboost_filesystem.dylib (file not found). warning: Unable to read symbols from "libboost_filesystem.dylib" (not yet mapped into memory). warning: Unable to read symbols for libboost_system.dylib (file not found). warning: Unable to read symbols from "libboost_system.dylib" (not yet mapped into memory). [Switching to process 43957 thread 0x0] dyld: Library not loaded: libboost_filesystem.dylib Referenced from: /Users/ssteele/Library/Developer/Xcode/DerivedData/MainProject-dqrhyuarllykslftblocjdzxlran/Build/Products/Debug/MainProject.app/Contents/MacOS/MainProject Reason: image not found 

I added a build step to copy dylib to the bundled Frameworks directory, this will not help. I changed this to copy them to the "Executables" directory, which also did not help.

The presence in the "Executable files" directory allows me to run the application from the terminal.

How can I get the dylib search application when starting from Finder / Xcode?

Background Information

I am using Xcode 4.2 on Lion and currently only target Lion. I created my shared libraries for the file system as follows:

 ./b2 threading=multi macosx-version=10.7 --with-filesystem stage 

This creates libboost_system.dylib, libboost_filesystem.dylib, as well as .a equivalents in the stage / lib directory, I refer to them directly in the project.

+6
source share
3 answers

Dynamic libraries (dylib) on OSX bake in the path from which they must be loaded. For instance...

/usr/lib/some_awesome.dylib .

When you reference dylib, the linker inserts this path into your executable as a place to search at runtime. This is good and easy with libs installed, but for a relative path, it is more complicated.

When you create boost files, they simply enter their names instead of the full or relative path (i.e. libboost_system.dylib , not /usr/lib/libboost_filesystem.dylib ). You must change this with the dll-path parameter, but which currently does not work .

To fix your problem, you need to either get the correct path relative to your application, built-in (e.g. @executable_path/libwhatever.dylib ) in dylib, as this will probably require the use of the dll-path bjam parameter, or you can fix yours instead to view elsewhere.

To do this, use the following: script step in your assembly:

install_name_tool -change libboost_filesystem.dylib @executable_path/libboost_filesystem.dylib$BUILT_PRODUCTS_DIR/$EXECUTABLE_PATH

Note that if you have multiple dylibs that reference each other with broken paths, you also need to fix the paths between them, for example.

install_name_tool -change libboost_system.dylib @executable_path/libboost_system.dylib$BUILT_PRODUCTS_DIR/$EXECUTABLE_FOLDER_PATH/libboost_filesystem.dylib

The following is a good article: Creating working dylibs

+12
source

The problem is that the boost must be set, for example. b2 ..... install . This copies the libraries and headers to / usr / local / lib and / usr / local / include.

OSX dynamic libraries run only from the directory for which they are created.

You can change the installation directory with the -prefix argument to format the assembly. However, libraries should still be in the same directory for all users.

There should be a way to create boost as a frame and / or @executable_path attachment in the library.

An alternative is to use forced static libraries - create static only or delete dynamic ones, Xcode searches dynamic until static. If you use static, then the library path does not matter at runtime, since all the code is now in the executable.

+1
source

I think you need to add the path to the directory where you saved libboost_filesystem.a in the "library search paths"

Click on your project profile β†’ build options β†’ expand "Search Path" β†’ "Library Search Paths"

0
source

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


All Articles