Re: CMake, file extensions

Richard Crozier <[email protected]>
Newsgroups gmane.comp.gnu.gnucap.devel
Message-ID <[email protected]>
On 13/02/17 16:21, Felix Salfelder wrote:
> On Mon, Feb 13, 2017 at 10:59:27AM +0000, Richard Crozier wrote:
>> You could do something similar to what matlab does. It uses custom suffix
>> for compiled shared libraries (mex files) but with a platform specific
>> extension (e.g. .mexw64 for win 64, .mexa64 for linux 64 bit etc.). Under
>> the hood they are just shared libraries.
>
> with this, i understand that in matlab-ui you do load("module"), and it
> then (roughly) calls dlopen("module" + ".mexa64").
>

With Matlab being proprietary I can't say exactly what happens, but 
'roughly' yes. You write a special entry function to your C or C++ code 
which includes a header file mex.h, and matlab compiles this for you 
into a shared library (just by passing the appropriate flags to normal 
compilers). In Matlab you then call it like you would any normal 
function without any suffix. In their case everything gets compiled 
statically into the shared library though so it is portable.

Octave (a free matlab alternative) also supports mex files but they've 
not gone down the route of different file extensions (a mistake in my 
opinion), but they might have code to copy.

> what if you wanted to dlopen just "module.so"? (would that be
> useful/worth supporting?)
>

I don't know, I don't have a strong opinion on this.

>> The advantage of this approach is that they can be on the Maltab search path
>> and easily found without mixing up with other shared libraries and different
>> platforms versions can coexist.
>
> indeed, with just .so/.dll/.dylib, we will not be able to have both
> 32bit and 64bit libraries in one directory... i totally see the use
> case.
>
> instead of using md.h, we should add a configure flag for that
> extension, so it will properly end up in the makefiles *and* in
> c_attach. then it can be anything, and also work for future whatever
> os/arch/abi combinations.
>
> thanks for sharing
> felix
>

Glad you found it useful!

Richard

-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.