Cross Compiling with NIF as compilation dependency

Looking at your project, I don’t think this is the issue, but let me start with a general statement since this comes up periodically.

For elixir_make projects, there are few important things to make NIFs work well with Nerves:

  1. Use macros like CC and CFLAGS instead of hardcoding calls to gcc. A lot of projects already do this, so sometimes this is really easy. See Environment variables — nerves v1.14.3.
  2. Put outputs in $(MIX_APP_PATH)/priv to keep host and target binaries separated. Nerves uses Mix’s MIX_TARGET feature which will create a new build directory for each target you compile for.
  3. Use Mix’s $(ERL_EI_INCLUDE_DIR) and $(ERL_EI_LIBDIR) instead of calling Erlang in the Makefile to figure out where Erlang header files and libraries are.

The standard procedure is to copy/paste a Makefile from another Elixir project to make it work with Nerves. For an example, see circuits_spi’s Makefile for a NIF example.

Nerves uses Buildroot to handle complicated C/C++ libraries. I took a look at libvips, and they made a few design decisions that I honestly don’t find enjoyable to work around. If I were required to use it, I’d do what was suggested and make a custom Nerves system to build libvips. The Buildroot package is at Buildroot libvips. Once that’s done, the Elixir Vix library would need to properly detect that it exists. That may work.

This is a long way of saying this:

  1. Give up trying to manually cross-compile libvips for Nerves
  2. If compiling with Nerves (checking $(CROSSCOMPILE) in the Makefile is probably easiest), make sure that the mode is PLATFORM_PROVIDED_LIBVIPS. The pkg-config call should look in the right place.
  3. If crosscompiling and not using a platform-provided libvips or it can’t be found, tell the user to build a custom Nerves system and BR2_PACKAGE_LIBVIPS=y to their nerves_defconfig. While at it, the user may want to also enable other libraries since libvips optionally works with so many.

Unfortunately, this will make Vix less interesting to Nerves users since it won’t work with the official Nerves systems, but it should work for anyone who needs it.