Skip to content

Instantly share code, notes, and snippets.

@vitorio
Last active August 28, 2016 00:30
Show Gist options
  • Save vitorio/d43575e56d0efe39a05d2e055ba8c496 to your computer and use it in GitHub Desktop.
Save vitorio/d43575e56d0efe39a05d2e055ba8c496 to your computer and use it in GitHub Desktop.
Compiling libnfc natively on OS X within your home directory

These instructions compile a native OS X version of libnfc that lives in your home directory, and which cannot be moved around, but should always be discoverable by applications.

Assumes OS X with Xcode or Xcode command-line tools, not macports or homebrew

To install Xcode command-line tools in recent versions of OS X, open Terminal, type xcode-select --install and click "Install"

Older versions of OS X may need to manually download disk images of older versions of Xcode and/or the Xcode command-line tools, as various certificates may have expired (e.g. 10.7.4 requires a manual install from the Xcode 4.6.2 command-line tools image)

Download latest pkg-config (tested with 0.29.1) from https://pkg-config.freedesktop.org/releases/?C=M;O=D

Download latest libusb (tested with 1.0.20) from https://sourceforge.net/projects/libusb/files/latest/download?source=files

Download latest libusb-compat (tested with 0.1.15) from https://sourceforge.net/projects/libusb/files/libusb-compat-0.1/

Download latest libnfc (tested with 1.7.1) from https://bintray.com/nfc-tools/sources/libnfc

Compile pkg-config, libusb, libusb-compat, libnfc

$ cd ~/Downloads/
$ cd pkg-config-0.29.1
$ ./configure --with-internal-glib --prefix=$HOME/
$ make
$ make install
$ cd ..
$ cd libusb-1.0.20
$ ./configure --prefix=$HOME/
$ make
$ make install
$ cd ..
$ cd libusb-compat-0.1.5
$ PKG_CONFIG=$HOME/bin/pkg-config ./configure --prefix=$HOME/
$ make
$ make install
$ cd ..
$ cd libnfc-1.7.1
$ PKG_CONFIG=$HOME/bin/pkg-config ./configure --prefix=$HOME/
$ make
$ make install

Now, your home directory has four new (probably) folders with pkg-config, libusb, libusb-compat, and libnfc in them:

$ ls -al
drwxr-xr-x   25 username  1897370479    850 Aug 27 00:24 bin
drwxr-xr-x    5 username  1897370479    170 Aug 27 00:24 include
drwxr-xr-x   15 username  1897370479    510 Aug 27 00:23 lib
drwxr-xr-x    5 username  1897370479    170 Aug 27 00:20 share

The ~/lib folder is in the default search path for dynamic libraries, so any software that uses libnfc or libusb should be able to automatically find it. These should always work without modification, even on OS X systems with System Integrity Protection (10.11 El Capitan and later), as long as they stay in ~/lib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment