2

I have written a simple application using the GPhoto2 Framework, and this works so long as the framework is in the location where it was originally compiled. I would like to move this inside the app bundle, though, so it does not need separate installation, so I need to make it work relative to this main executable.

Unfortunately the framework is not an Xcode project. It uses a script to build, so I cannot simply change the installation directory build setting, which is the solution that I have frequently seen while searching for an answer. Being quite new to Xcode and Mac programming it is also beyond my abilities to know how to convert the framework into an Xcode project.

The other advice I came across was to use install_name_tool to update the library ID and dependencies, replacing the absolute paths with ones of the form "@executable_path/../Frameworks/GPhoto2.framework". The framework is not a single binary, but contains a number of .dylib and .so libraries, but updating all of these has only been half successful.

I have set Xcode to copy the framework into the app bundle when it builds it. Then if I remove the framework from its originally compiled location the application fails to load, with the report generated by OS X saying the libgphoto2 library can no longer be found, as to be expected.

If I then use install_name_tool to update the references in all of the framework libraries inside the app bundle, and also in the app binary itself, then the application will load but fails to find any camera connected. Using otool I am able to verify that all references have correctly been changed.

But if I replace a copy of the framework to its original location it then works properly again, recognizing connected cameras, regardless of whether that framework uses relative or absolute locations. Clearly it is still looking at this location despite loading. I have even tried removing each of the individual library files from the framework in its original location in turn to see if the problem was just the result of a dependency in of these, but no matter which is missing the app will not work.

Incidentally, if I build the app using an updated version of the framework, it fails saying it cannot find the library "@executable_path/../Frameworks/GPhoto2.framework/prefix/lib/libgphoto2.2.dylib"

Am I doing something wrong or missing a step, or is what I am trying to do impossible for frameworks created outside Xcode?

Matteo
  • 37,680
  • 11
  • 100
  • 115
Rebecka
  • 1,213
  • 8
  • 14
  • After further examination I have found the specific problem. When I did my file by file test to see what needed to be in the original framework location I unfortunately had one there with hardcoded paths. So the private framework loaded something with a hardcoded dependency giving a false impression of a requirement. – Rebecka Feb 18 '13 at 11:48
  • Sorry, never realized comments could not include new lines. Testing again the only requirement on the original location are the .so files, using strings I can confirm their locations are hardcoded into certain libraries. Is there an official way to be able to update these? If not is it possible to overwrite the paths with relative ones with a binary editor, and in which case relative to what? – Rebecka Feb 18 '13 at 11:56

1 Answers1

0

In case someone comes across this future, the answer to my question was that I was doing nothing wrong. The problem was that the .so files were being loaded by libtool ltdl, at it requires absolute paths so these were being set at build time.

I patched the files gphoto2-abilities-list.c and gphoto2-port-info-list.c so that at runtime it would combine the relative library paths with the executable location. As a result I also needed to increase the FILENAME_MAX constant to allow it the mail application to run from, for example, the Desktop. But this, along with the use of install_name_tool allowed me to add GPhoto2 as a framework inside my application without needing any external dependencies.

The final problem of not being able to build my app in XCode with the framework after using install_name_tool remained, but for that I just used the original framework build, then after compilation I updated the references in the copied framework at the same time as I updated the ones in the main executable.

Rebecka
  • 1,213
  • 8
  • 14