Show how to call a function in a shared library (without dynamically linking to it at compile-time). In particular, show how to call the shared library function if the library is available, otherwise use an internal equivalent function.

This is a special case of calling a foreign language function where the focus is close to the ABI level and not at the normal API level.



Related task

 OpenGL -- OpenGL is usually maintained as a shared library.


-INCLUDE 'ffi.sno'
 
    ffi_m = FFI_DLOPEN('/usr/lib/x86_64-linux-gnu/libm.so')
    ffi_m_hypot = FFI_DLSYM(ffi_m, 'hypot')
    DEFINE_FFI('hypot(double,double)double', ffi_m_hypot)
 
    OUTPUT = hypot(1,2)
    OUTPUT = hypot(2,3)
    OUTPUT = hypot(3,4)
    OUTPUT = hypot(4,5)
 
END