1

I have built a cross-platform C++ application that uses some external libraries (e.g. Boost, GLFW). My intention is to create an archive, for instance a .zip file, for each operating system so that the end user only has to extract this package in order to run the application. I am facing a problem related to dynamic linking of the libraries.

When I built the application in Linux, I use the -Wl,rpath option to specify the run time library search path. On Windows, I can simply place all relevant .dll files in the same folder as where the executable resides. Now on MacOS, I am facing the issue that the libraries are referred to by absolute paths. Those paths may be valid for my system, but not necessarily for the system of the user. I already found that I can change those paths to relative paths using install_name_tool.

The remaining difficulty is that I have to change quite a lot of these references. Besides the references in the executable, some of the libraries have dependencies themselves which are also defined by absolute paths.

My question is: Is there an efficient and smart way to set relative paths instead of absolute paths for the libraries on MacOS?

Ivo Filot
  • 228
  • 5
  • 13
  • That's the thing, you might not be able to guarantee that the user actually has the library on their system; it might be best to include them with the application. – l'L'l Nov 18 '16 at 08:42
  • I fully agree! That is what I am doing; I am adding those libraries to the archive. But the executable is referring, by default, to the absolute paths of the libraries on my system. Changing these paths to a folder relative to where the executable resides is at the moment a tedious job as I have to go through all the libraries and change all those references one-by-one. – Ivo Filot Nov 18 '16 at 08:44
  • Using `otool -L` can help tremendously in the process (http://stackoverflow.com/q/9263256/499581), in addition the `-rpath` clause might allow you to be more generalized in that you provide a list of possible locations to the executable as to where to find dynamic libraries (https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/RunpathDependentLibraries.html#//apple_ref/doc/uid/TP40008306-SW1). – l'L'l Nov 18 '16 at 09:02

0 Answers0