auriamg / macdylibbundler

Utility to ease bundling libraries into executables for OSX
MIT License
550 stars 83 forks source link

bundling qemu doesn't rewrite libhogweed libnettle deps correctly #23

Closed gui1117 closed 6 years ago

gui1117 commented 7 years ago

after bundling qemu-img installed via homebrew libhogweed still point to /usr/local/Cellar/nettle/3.3/lib/libnettle.6.dylib

$ otool -L libhogweed.4.3.dylib 
libhogweed.4.3.dylib:
    @loader_path/libhogweed.4.3.dylib (compatibility version 4.0.0, current version 4.3.0)
    /usr/local/Cellar/nettle/3.3/lib/libnettle.6.dylib (compatibility version 6.0.0, current version 6.3.0)
    @loader_path/libgmp.10.dylib (compatibility version 14.0.0, current version 14.1.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.0.0)
programmingkidx commented 6 years ago

Here is my libhogweed without changes: otool -L /usr/local/Cellar/nettle/2.7.1/lib/libhogweed.2.5.dylib /usr/local/Cellar/nettle/2.7.1/lib/libhogweed.2.5.dylib: /usr/local/lib/libhogweed.2.dylib (compatibility version 2.0.0, current version 2.5.0) /usr/local/Cellar/nettle/2.7.1/lib/libnettle.4.dylib (compatibility version 4.0.0, current version 4.7.0) /usr/local/lib/libgmp.10.dylib (compatibility version 13.0.0, current version 13.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.11)

Here is my libhogweed with changes made by dylibbundler: /Users/user/Documents/libs/libhogweed.2.5.dylib: @executable_path/libs/libhogweed.2.5.dylib (compatibility version 2.0.0, current version 2.5.0) /usr/local/Cellar/nettle/2.7.1/lib/libnettle.4.dylib (compatibility version 4.0.0, current version 4.7.0) @executable_path/libs/libgmp.10.dylib (compatibility version 13.0.0, current version 13.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.11)

My libnettle.4.dylib path is not changed also. Looking at the output of dylibbundler I saw a bunch of lines that didn't make sense to me. They are all making changes to libhogweed, but these paths are not even in the dylib:

cp -n /usr/local/Cellar/nettle/2.7.1/lib/libhogweed.2.5.dylib libs/libhogweed.2.5.dylib chmod +w libs/libhogweed.2.5.dylib install_name_tool -id @executable_path/libs/libhogweed.2.5.dylib libs/libhogweed.2.5.dylib

programmingkidx commented 6 years ago

I found the dylibbundler's file Dependency.cpp had a bug in the Dependency::mergeIfSameAs() function that would add all the symbolic links to another symbolic links Dependency object instead of writing them to the dylib object.

If you download dylibbundler's source and replace the mergeIfSameAs() function with this one in the Dependency.cpp file, libhogweed's paths will be correctly set:

// Compares the given Dependency with this one. If both refer to the same file,
// it returns true and merges both entries into one.
bool Dependency::mergeIfSameAs(Dependency& dep2)
{
    if(dep2.getOriginalFileName().compare(filename) == 0)
    {
        const int samount = getSymlinkAmount();
        for(int n=0; n<samount; n++) {
            dep2.addSymlink(getSymlink(n)); // FIXME - there may be duplicate symlinks
        }
        return true;
    }
    return false;
}
auriamg commented 6 years ago

Fixed by pull request #25