If Pony code calls FFI functions, then those functions, or rather the libraries containing them, must be linked into the Pony program.

Use for external libraries

To link an external library to Pony code another variant of the use command is used. The “lib” specifier is used to tell the compiler you want to link to a library. For example:

  1. use "lib:foo"

As with other use commands a condition may be specified. This is particularly useful when the library has slightly different names on different platforms.

Here’s a real example from the standard library:

  1. use "path:/usr/local/opt/libressl/lib" if osx
  2. use "lib:ssl" if not windows
  3. use "lib:crypto" if not windows
  4. use "lib:libssl-32" if windows
  5. use "lib:libcrypto-32" if windows
  6. primitive _SSLInit
  7. """
  8. This initialises SSL when the program begins.
  9. """
  10. fun _init() =>
  11. @SSL_load_error_strings[None]()
  12. @SSL_library_init[I32]()

On Windows, we use the libraries “libssl-32” and “libcrypto-32” and on other platforms we use “ssl” and “crypto”. These contain the FFI functions SSL_library_init and SSL_load_error_strings (amongst others).

By default the Pony compiler will look for the libraries to link in the standard places, however, that is defined on the build platform. However, it may be necessary to look in extra places. The use "path:..." command allows this. The specified path is added to the library search paths for the remainder of the current file. The example above uses this to add the path “/usr/local/opt/libressl/lib” for OSX. This is required because the library is provided by brew, which installs things outside the standard library search paths.

If you are integrating with existing libraries, that is all you need to do.