Create a gist now

Instantly share code, notes, and snippets.

Building GnuTLS on Mac OS X

Preparing the Build Environment

cd ~/Desktop
mkdir wget-build
cd wget-build

Building & Installing GMP 5.0.2

curl -O ftp://ftp.gmplib.org/pub/gmp-5.0.2/gmp-5.0.2.tar.bz2
tar xjf gmp-5.0.2.tar.bz2
pushd gmp-5.0.2
CC=gcc-4.2 CXX=g++4.2 ./configure --prefix=/usr/local
make
sudo make install
popd

Building & Installing Libnettle 2.4

curl -O http://www.lysator.liu.se/~nisse/archive/nettle-2.4.tar.gz
tar xzf nettle-2.4.tar.gz
pushd nettle-2.4
CFLAGS="-m64" ./configure --prefix=/usr/local --disable-assembler
make
sudo make install
popd

Building & Installing GnuTLS 2.12.12

curl -O http://ftp.gnu.org/gnu/gnutls/gnutls-2.12.12.tar.bz2
tar xjf gnutls-2.12.12.tar.bz2
pushd gnutls-2.12.12
CFLAGS="-m64" CXXFLAGS="-m64" ./configure --prefix=/usr/local --without-p11-kit
make
sudo make install
popd
@jaycode
jaycode commented Jun 12, 2012

If you found this error:

checking compiler gcc-4.2 ... no
configure: error: could not find a working compiler, see config.log for details

Try this:

sudo ln -s /Developer/usr/bin/gcc-4.2 /usr/bin/gcc-4.2

Which symlink /Developer/usr/bin/gcc-4.2 to /usr/bin/gcc-4.2 so it can be used in ./configure

@morgant
Owner
morgant commented Jun 20, 2012

I hadn't personally run into that, but it's definitely worth noting.

@dyollluap

worked perfectly, thank you for making the effort to document your method so clearly!

@a34729t
a34729t commented Jan 14, 2013

This also works with gnutls 3.1.6 (requires libnettle 2.5) on OSX 10.6. Thanks!

ftp://ftp.gnutls.org/gcrypt/gnutls/v3.1/gnutls-3.1.6.tar.xz
http://www.lysator.liu.se/~nisse/archive/nettle-2.5.tar.gz

@dieza
dieza commented Mar 14, 2013

On Mountain Lion, make check stalls at t-cdiv_ui as reported elsewhere [1], but doing
CC=clang CXX=clang ./configure --prefix=/usr/local
all test are passed. It throws more warnings with clang that with gcc-4.2 but 'make check' runs

[1] http://gmplib.org/list-archives/gmp-bugs/2011-November/002442.html

@Tristor
Tristor commented Jun 8, 2013

I can't get the latest GnuTLS to compile, but configure succeeds if I take some extra steps. Without extra steps, the configure script will fail saying it can't find Libnettle 2.7 despite Nettle compiling fine. I'm trying to build GnuTLS-3.2.1 with GMP-5.1.2 and Nettle-2.7.1 (current latest release of all 3) on OS X 10.7.5

To get around this, you must do two things, one you must set your pkg-config search path to include /usr/local/lib, which you can do with
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/

Once you've done that, if you do the following configure, it will generate makefiles successfully, but can't compile:

CFLAGS="-m64 -pipe -O2 -march=core2" CXXFLAGS="${CFLAGS}" CPPFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib" ./configure --prefix=/usr/local --without-p11-kit

You end up with the following error:

  CCLD   libgnutls.la
/usr/bin/nm: no name list
/usr/bin/nm: no name list
/usr/bin/nm: no name list
/usr/bin/nm: no name list
/usr/bin/nm: no name list
/usr/bin/nm: no name list
/usr/bin/nm: no name list
/usr/bin/nm: no name list
/usr/bin/nm: no name list
/usr/bin/nm: no name list
Undefined symbols for architecture x86_64:
  "___gmpz_init", referenced from:
      __wrap_nettle_pk_derive in libcrypto.a(pk.o)
      _wrap_nettle_pk_verify_params in libcrypto.a(pk.o)
      _wrap_nettle_hash_algorithm in libcrypto.a(pk.o)
      __wrap_nettle_pk_sign in libcrypto.a(pk.o)
      __wrap_nettle_pk_encrypt in libcrypto.a(pk.o)
      _wrap_nettle_mpi_new in libcrypto.a(mpi.o)
      _wrap_nettle_mpi_mod in libcrypto.a(mpi.o)
      ...
  "___gmpz_clear", referenced from:
      __wrap_nettle_pk_derive in libcrypto.a(pk.o)
      _wrap_nettle_hash_algorithm in libcrypto.a(pk.o)
      __wrap_nettle_pk_sign in libcrypto.a(pk.o)
      __wrap_nettle_pk_encrypt in libcrypto.a(pk.o)
      _wrap_nettle_mpi_release in libcrypto.a(mpi.o)
      _wrap_nettle_generate_group in libcrypto.a(mpi.o)
  "___gmpz_invert", referenced from:
      _wrap_nettle_pk_fixup in libcrypto.a(pk.o)
      _wrap_nettle_pk_verify_params in libcrypto.a(pk.o)
  "___gmpz_cmp", referenced from:
      _wrap_nettle_pk_verify_params in libcrypto.a(pk.o)
      _wrap_nettle_mpi_cmp in libcrypto.a(mpi.o)
  "___gmpz_powm", referenced from:
      _wrap_nettle_hash_algorithm in libcrypto.a(pk.o)
      _wrap_nettle_mpi_powm in libcrypto.a(mpi.o)
      _wrap_nettle_generate_group in libcrypto.a(mpi.o)
  "___gmpz_init2", referenced from:
      _wrap_nettle_mpi_new in libcrypto.a(mpi.o)
      _wrap_nettle_mpi_mod in libcrypto.a(mpi.o)
      _wrap_nettle_mpi_set_ui in libcrypto.a(mpi.o)
      _wrap_nettle_mpi_powm in libcrypto.a(mpi.o)
      _wrap_nettle_mpi_addm in libcrypto.a(mpi.o)
      _wrap_nettle_mpi_subm in libcrypto.a(mpi.o)
      _wrap_nettle_mpi_mulm in libcrypto.a(mpi.o)
      ...
  "___gmpz_cmp_ui", referenced from:
      _wrap_nettle_mpi_cmp_ui in libcrypto.a(mpi.o)
      _wrap_nettle_generate_group in libcrypto.a(mpi.o)
  "___gmpz_sizeinbase", referenced from:
      _wrap_nettle_mpi_mod in libcrypto.a(mpi.o)
      _wrap_nettle_mpi_get_nbits in libcrypto.a(mpi.o)
      _wrap_nettle_mpi_powm in libcrypto.a(mpi.o)
      _wrap_nettle_mpi_addm in libcrypto.a(mpi.o)
      _wrap_nettle_mpi_subm in libcrypto.a(mpi.o)
      _wrap_nettle_mpi_mulm in libcrypto.a(mpi.o)
      _wrap_nettle_mpi_add in libcrypto.a(mpi.o)
      ...
  "___gmpz_mod", referenced from:
      _wrap_nettle_mpi_mod in libcrypto.a(mpi.o)
  "___gmpz_set", referenced from:
      _wrap_nettle_mpi_set in libcrypto.a(mpi.o)
  "___gmpz_set_ui", referenced from:
      _wrap_nettle_mpi_set_ui in libcrypto.a(mpi.o)
  "___gmpz_add", referenced from:
      _wrap_nettle_mpi_addm in libcrypto.a(mpi.o)
      _wrap_nettle_mpi_add in libcrypto.a(mpi.o)
  "___gmpz_fdiv_r", referenced from:
      _wrap_nettle_mpi_addm in libcrypto.a(mpi.o)
      _wrap_nettle_mpi_subm in libcrypto.a(mpi.o)
      _wrap_nettle_mpi_mulm in libcrypto.a(mpi.o)
      _wrap_nettle_generate_group in libcrypto.a(mpi.o)
  "___gmpz_sub", referenced from:
      _wrap_nettle_mpi_subm in libcrypto.a(mpi.o)
      _wrap_nettle_mpi_sub in libcrypto.a(mpi.o)
  "___gmpz_mul", referenced from:
      _wrap_nettle_mpi_mulm in libcrypto.a(mpi.o)
      _wrap_nettle_mpi_mul in libcrypto.a(mpi.o)
      _wrap_nettle_generate_group in libcrypto.a(mpi.o)
  "___gmpz_add_ui", referenced from:
      _wrap_nettle_mpi_add_ui in libcrypto.a(mpi.o)
      _wrap_nettle_generate_group in libcrypto.a(mpi.o)
  "___gmpz_sub_ui", referenced from:
      _wrap_nettle_mpi_sub_ui in libcrypto.a(mpi.o)
  "___gmpz_mul_ui", referenced from:
      _wrap_nettle_mpi_mul_ui in libcrypto.a(mpi.o)
      _wrap_nettle_generate_group in libcrypto.a(mpi.o)
  "___gmpz_cdiv_q", referenced from:
      _wrap_nettle_mpi_div in libcrypto.a(mpi.o)
  "___gmpz_probab_prime_p", referenced from:
      _wrap_nettle_prime_check in libcrypto.a(mpi.o)
      _wrap_nettle_generate_group in libcrypto.a(mpi.o)
  "___gmpz_setbit", referenced from:
      _wrap_nettle_generate_group in libcrypto.a(mpi.o)
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make[3]: *** [libgnutls.la] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
@grok
grok commented Jun 22, 2013
First, use curl to download the latest wget source:
curl -O http://ftp.gnu.org/gnu/wget/wget-1.13.4.tar.gz

Next we use tar to uncompress the files you just downloaded:
tar -xzf wget-1.13.4.tar.gz

Use cd to change to the directory:
cd wget-1.13.4

Configure with the appropriate –with-ssl flag to prevent a “GNUTLS not available” error:
./configure --with-ssl=openssl

Build the source:
make

Install wget, it ends up in /usr/local/bin/:
sudo make install

Confirm everything worked by running wget:
wget --help

Clean up by removing wget source files when finished:
cd .. && rm -rf wget*
@retrocar66

This worked for me.

Why does setting --with-ssl prevent the error? Does it just remove the GNUTLS dependency?

@mario-grgic

./configure --with-ssl=openssl

Apple OpenSSL implementation already has TSL library.

@francwalter
francwalter commented Jun 30, 2016 edited

I run into an error when try to make nettle-2.4 on my MacBook with OS 10.11.5:

In file included from /usr/local/include/gmp.h:50:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstddef:46:9: error: no member named
      'ptrdiff_t' in the global namespace
using ::ptrdiff_t;
      ~~^
1 error generated.

I could compile the previous library (GMP 5.0.2) but I had to install gcc-4.2 through brew, the hint from @jaycode (from 12 Jun 2012) didn't help, there was no more 4.2 on my system, I guess this is too old.
What could I do? I don't understand this error.
Or is there another way to get gnutls on Mac OS 10.11.5?
Thanks

EDIT 2016-07-04: never mind, I let go my plan of compiling inadyn on Mac, where I need gnutls. There are too many other issues anyway.

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