Uploaded image for project: 'Log4cxx'
  1. Log4cxx
  2. LOGCXX-346

Mac XCode project doesn't define the Dynamic Library Install Name correctly (nor the installation directory)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Won't Fix
    • 0.10.0
    • None
    • Build
    • None
    • Mac OS X 10.6.1, but I see no reason for this problem not to be happening under 10.5.x also
      I use XCode 3.2.1

    Description

      The provided XCode project builds the log4cxx dynamic library to be installed in the ~/bin directory. This means that any client app will not be able to run unless exists on the client computer a user with the same name as the one who built log4xx, in which the bin subdirectory exists, in which log4cxx.dylib has been put, all with read permissions. The likelihood of that is... low.

      The fix is very simple: in the XCode project settings:

      1- clear the "Installation Directory" setting (under category Deployment) (currently ~/bin). XCode will reset it to the more correct /usr/local/lib. But in any case please note that this setting will not be used if you do step 2.

      2- essential: change the "Dynamic Library Install Name" (under category Linking). It must now read:

      @rpath/$(EXECUTABLE_PATH)

      That way the same log4cxx.dylib works whether it is installed in a system location such as /usr/lib or inside a client code bundle, in a way that keeps the client code totally independent from its own location in the file system.

      Explanation: the macro $(EXECUTABLE_PATH) will be replaced by XCode to be the name of the dynamic library, "log4cxx.dylib" in our case. the variable @rpath is not a macro, but a run time variable that will be expanded by the loader from the client code to be... whatever the client code has set.

      Typically, the client code will set it (under its XCode project "Runpath Search Paths" setting) to be a search list that include /usr/lib/ and /usr/local/lib, but also, and more importantly, its own bundle directory. Here is what I set it mine to:

      @loader_path/../Libraries

      And then of course, I put log4cxx.dylib in my code bundle at the relative path Contents/Libraries/log4cxx.dylib

      @loader_path is (another) runtime variable expanded by the loader which represent the directory where the executable is. For a normal app named "sample", this directory will be for example:

      /Applications/sample.app/Contents/MacOS

      So @loader_path/../Libraries expands at runtime to be:

      /Applications/sample.app/Contents/Libraries/log4cxx.dylib

      Regards.

      JDM

      Attachments

        Activity

          People

            carnold@apache.org Curt Arnold
            jdmuys Jean-Denis Muys
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 5m
                5m
                Remaining:
                Remaining Estimate - 5m
                5m
                Logged:
                Time Spent - Not Specified
                Not Specified