octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Towards more portable MEX compilations (with focus on the Mac)


From: mcg
Subject: Towards more portable MEX compilations (with focus on the Mac)
Date: Tue, 11 Feb 2014 18:50:35 -0800 (PST)

In my CVX package I distribute precompiled MEX files for 32- and 64- bit versions of Mac, Windows, and Linux MATLAB. In the process of determining how to do the same for Octave, I found a couple of different issues that complicate matters.

  1. The 'mkoctfile' routine links the compiled code to every dependency that the current installation of Octave has, even if those libraries are not needed by the code itself. What happens if a particular user's Octave build does not link to the same set of dependencies? I don't have a complete understanding about how dynamic library dependency resolution is performed---whether it occurs on load, or is lazily done as calls are made to those dependencies. If it's the former, then MEX/OCT files must be linked to the least common denominator of dependencies if they have any chance of being binary portable.

    It should be noted that MATLAB takes the minimal approach to linking; even LAPACK and BLAS must be explicitly requested (although you can link to the MATLAB image of BLAS/LAPACK). It's also important to point out that not linking to the other dependencies does *not* prevent them from being used---they just have to be called through the interfaces provided by lib octave or liboctinterp.

  2. On the Mac, dynamic library path resolution is a bit tricky. For a package like Octave, the best way to go is to use @rpath constructs in the dynamic libraries (liboctave/libinterp), and then give the executable an rpath (likely using an @executable_path construct) that points all dynamically loaded objects to the library install directory. Unfortunately, GNU libtool provides no way to insert these constructs into the library and/or executable. (I've submitted a patch, but I'm not optimistic.) I don't think Linux really has an issue here; I don't yet know about Windows.

    The Mac Ports folks use the @rpath approach when building their app bundles; you can see the hoops they jump through here. JWE pointed me to this link. Of course, the Mac app builders have a bigger challenge, because they need to include every non-system Octave dependency in the package. So they have to employ these techniques not just for liboctave/liboctinterp, but every non-system library.

Can these issues be at least partially solved in the build itself? I have a couple of proposals that at least partially address the problem:

Together these accomplish exactly what I'm looking for at the moment. If I look at the dependencies for one of my Mex files, I see this:

>> system('otool -L cvx_bcompress_mex.mex')
cvx_bcompress_mex.mex:
        @rpath/liboctinterp.2.dylib (compatibility version 3.0.0, current version 3.0.0)
        @rpath/liboctave.2.dylib (compatibility version 3.0.0, current version 3.0.0)
        /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
This is perfect: there are no extra libraries linked, and the path to the Octave libraries can be picked up at load time, thanks to the @rpath constructs. This message has gone long enough. What are your thoughts---especially those who work with the Mac, but anyone who might be affected by these kinds of improvements.

Thanks for your time, everyone!

Regards,
Michael Grant
http://cvxr.com
address@hidden



View this message in context: Towards more portable MEX compilations (with focus on the Mac)
Sent from the Octave - Maintainers mailing list archive at Nabble.com.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]