title: Porting GnuTLS to Android
body: <p>I'm trying to build GnuTLS for Android using Android NDK as part of my project. I've saw some examples on <a href="http://odroid.foros-phpbb.com/t338-ffmpeg-compiled-with-android-ndk%5d" rel="nofollow">how libffmpeg is compile using Android NDK</a> and porting of OpenSSL to Android. Is it possible for GnuTLS too?</p>
  
  <p>I've tried compiling GnuTLS soruce using Android NDK r7b with no results, some files just refuse to compile. Do I need to remove some of the features or is there any way to do so? Would appreciate some advice on this. Thanks in advance.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I am using the following <code>Android.mk</code> file with the order of source files based on the output from command <code>make</code> when compiling on my Ubuntu system:</p>
  
  <pre><code>LOCAL_PATH := $(call my-dir)
  include $(CLEAR_VARS)
  
  LOCAL_MODULE    := GnuTLS
  LOCAL_SRC_FILES := gl/argp-ba.c \
  gl/argp-eexst.c \
  gl/argp-fmtstream.c \
  gl/argp-fs-xinl.c \
  gl/argp-parse.c \
  gl/argp-pin.c \
  gl/argp-pv.c \
  gl/argp-pvh.c \
  gl/argp-xinl.c \
  gl/base64.c \
  gl/c-ctype.c \
  gl/dirname-lgpl.c \
  gl/basename-lgpl.c \
  gl/stripslash.c \
  gl/fd-hook.c \
  gl/fseterr.c \
  gl/gettime.c \
  gl/printf-frexp.c \
  gl/printf-frexpl.c \
  gl/progname.c \
  gl/sockets.c \
  gl/version-etc-fsf.c \
  gl/asnprintf.c \
  gl/isnanl.c \
  gl/printf-args.c \
  gl/printf-parse.c \
  gl/strerror.c \
  gl/vasnprintf.c \
  gl/vfprintf.c \
  gl/vprintf.c \
  lib/x509/key_encode.c \
  lib/x509/key_decode.c \
  lib/x509/crl.c \
  lib/x509/crl_write.c \
  lib/x509/crq.c \
  lib/x509/dn.c \
  lib/x509/extensions.c \
  lib/x509/mpi.c \
  lib/x509/pbkdf2-sha1.c \
  lib/x509/pkcs12.c \
  lib/x509/pkcs12_bag.c \
  lib/x509/pkcs12_encr.c \
  lib/x509/pkcs7.c \
  lib/x509/privkey.c \
  lib/x509/privkey_pkcs8.c \
  lib/x509/rfc2818_hostname.c \
  lib/x509/sign.c \
  lib/x509/verify.c \
  lib/x509/x509.c \
  lib/x509/x509_write.c \
  lib/x509/verify-high.c \
  lib/accelerated/x86/sha-padlock.c \
  lib/accelerated/x86/hmac-padlock.c \
  lib/accelerated/x86/aes-x86.c \
  lib/accelerated/x86/aes-padlock.c \
  lib/accelerated/x86/aes-gcm-padlock.c \
  lib/accelerated/accelerated.c \
  lib/accelerated/cryptodev.c \
  lib/accelerated/cryptodev-gcm.c \
  lib/auth/anon.c \
  lib/auth/cert.c \
  lib/auth/dhe.c \
  lib/auth/dhe_psk.c \
  lib/auth/psk.c \
  lib/auth/psk_passwd.c \
  lib/auth/rsa.c \
  lib/auth/rsa_export.c \
  lib/auth/srp.c \
  lib/auth/srp_passwd.c \
  lib/auth/srp_rsa.c \
  lib/auth/srp_sb64.c \
  lib/auth/anon_ecdh.c \
  lib/ext/max_record.c \
  lib/ext/cert_type.c \
  lib/ext/server_name.c \
  lib/ext/signature.c \
  lib/ext/safe_renegotiation.c \
  lib/ext/session_ticket.c \
  lib/ext/ecc.c \
  lib/algorithms/cert_types.c \
  lib/algorithms/ciphers.c \
  lib/algorithms/ciphersuites.c \
  lib/algorithms/ecc.c \
  lib/algorithms/kx.c \
  lib/algorithms/mac.c \
  lib/algorithms/protocols.c \
  lib/algorithms/publickey.c \
  lib/algorithms/secparams.c \
  lib/algorithms/sign.c \
  lib/extras/randomart.c \
  lib/minitasn1/version.c \
  lib/opencdk/kbnode.c \
  lib/opencdk/sig-check.c \
  lib/opencdk/hash.c \
  lib/opencdk/keydb.c \
  lib/opencdk/pubkey.c \
  lib/opencdk/stream.c \
  lib/opencdk/write-packet.c \
  lib/opencdk/seskey.c \
  lib/opencdk/literal.c \
  lib/opencdk/new-packet.c \
  lib/opencdk/read-packet.c \
  lib/openpgp/compat.c \
  lib/openpgp/gnutls_openpgp.c \
  lib/nettle/pk.c \
  lib/nettle/mpi.c \
  lib/nettle/mac.c \
  lib/nettle/cipher.c \
  lib/nettle/rnd.c \
  lib/nettle/init.c \
  lib/nettle/egd.c \
  lib/nettle/multi.c \
  lib/nettle/ecc_free.c \
  lib/nettle/ecc_make_key.c \
  lib/nettle/ecc_shared_secret.c \
  lib/nettle/ecc_map.c \
  lib/nettle/ecc_mulmod.c \
  lib/nettle/ecc_points.c \
  lib/nettle/ecc_projective_dbl_point_3.c \
  lib/nettle/ecc_projective_add_point.c \
  lib/nettle/ecc_projective_check_point.c \
  lib/nettle/ecc_sign_hash.c \
  lib/nettle/ecc_verify_hash.c \
  lib/nettle/ecc_mulmod_timing.c \
  lib/gnutls_record.c \
  lib/gnutls_compress.c \
  lib/debug.c \
  lib/gnutls_cipher.c \
  lib/gnutls_mbuffers.c \
  lib/gnutls_buffers.c \
  lib/gnutls_handshake.c \
  lib/gnutls_num.c \
  lib/gnutls_dh.c \
  lib/gnutls_kx.c \
  lib/gnutls_priority.c \
  lib/gnutls_hash_int.c \
  lib/gnutls_cipher_int.c \
  lib/gnutls_session.c \
  lib/gnutls_db.c \
  lib/gnutls_extensions.c \
  lib/gnutls_auth.c \
  lib/gnutls_v2_compat.c \
  lib/gnutls_datum.c \
  lib/gnutls_session_pack.c \
  lib/gnutls_mpi.c \
  lib/gnutls_pk.c \
  lib/gnutls_constate.c \
  lib/gnutls_anon_cred.c \
  lib/pkix_asn1_tab.c \
  lib/gnutls_asn1_tab.c \
  lib/gnutls_mem.c \
  lib/gnutls_ui.c \
  lib/gnutls_sig.c \
  lib/gnutls_ecc.c \
  lib/gnutls_dh_primes.c \
  lib/gnutls_state.c \
  lib/gnutls_x509.c \
  lib/gnutls_rsa_export.c \
  lib/gnutls_helper.c \
  lib/gnutls_supplemental.c \
  lib/random.c \
  lib/crypto-api.c \
  lib/gnutls_privkey.c \
  lib/gnutls_pcert.c \
  lib/gnutls_pubkey.c \
  lib/hash.c \
  lib/gnutls_dtls.c \
  lib/system_override.c \
  lib/crypto-backend.c \
  lib/gnutls_srp.c \
  lib/gnutls_psk.c\
  extra/gnutls_openssl.c \
  extra/openssl_compat.c \
  doc/examples/ex-alert.c \
  doc/examples/ex-pkcs12.c \
  doc/examples/ex-session-info.c \
  doc/examples/ex-x509-info.c \
  doc/examples/ex-verify.c \
  doc/examples/tcp.c \
  doc/examples/udp.c \
  doc/examples/ex-pkcs11-list.c \
  doc/examples/verify.c \
  doc/examples/ex-verify-ssh.c \
  doc/examples/ex-serv-dtls.c \
  doc/examples/print-ciphersuites.c \
  doc/examples/ex-client-resume.c \
  doc/examples/ex-client-dtls.c \
  doc/examples/ex-cert-select.c \
  doc/examples/ex-client-x509.c \
  doc/examples/ex-client-anon.c \
  doc/examples/ex-serv-anon.c \
  doc/examples/ex-serv-pgp.c \
  doc/examples/ex-client-psk.c \
  doc/examples/ex-serv-psk.c \
  doc/examples/ex-client-srp.c \
  doc/examples/ex-serv-srp.c \
  doc/examples/ex-ocsp-client.c \
  tests/utils.c \
  gl/argp-help.c \
  gl/read-file.c \
  gl/version-etc.c \
  lib/x509/ocsp.c \
  lib/ext/srp.c \
  lib/opencdk/armor.c \
  lib/opencdk/misc.c \
  lib/x509_b64.c \
  lib/gnutls_cert.c \
  lib/gnutls_str.c \
  lib/locks.c \
  lib/verify-tofu.c \
  src/certtool-cfg.c \
  gl/getopt.c \
  lib/x509/output.c \
  lib/x509/ocsp_output.c \
  lib/auth/dh_common.c \
  lib/auth/ecdh_common.c \
  lib/minitasn1/decoding.c \
  lib/minitasn1/gstr.c \
  lib/minitasn1/errors.c \
  lib/minitasn1/parser_aux.c \
  lib/minitasn1/structure.c \
  lib/minitasn1/element.c \
  lib/minitasn1/coding.c \
  lib/openpgp/pgp.c \
  lib/openpgp/pgpverify.c \
  lib/openpgp/extras.c \
  lib/openpgp/privkey.c \
  lib/openpgp/output.c \
  lib/gnutls_errors.c \
  lib/gnutls_global.c \
  lib/gnutls_alert.c \
  lib/system.c \
  src/libopts/libopts.c \
  src/serv-args.c \
  src/srptool-args.c \
  src/ocsptool-args.c \
  src/psk-args.c \
  src/cli-args.c \
  src/cli-debug-args.c \
  src/certtool-args.c \
  
  include $(BUILD_SHARED_LIBRARY)
  </code></pre>
  
  <p>in which I get the following errors:</p>
  
  <pre><code>Compile thumb  : GnuTLS &lt;= version-etc.c
  In file included from /home/dazhang/Desktop/Android/GnuTLS/jni/gl/gettext.h:25,
                   from /home/dazhang/Desktop/Android/GnuTLS/jni/gl/version-etc.c:32:
  /home/dazhang/Desktop/Android/GnuTLS/jni/libintl.h: In function 'gettext':
  /home/dazhang/Desktop/Android/GnuTLS/jni/libintl.h:53: error: expected declaration specifiers before '__attribute_format_arg__'
  /home/dazhang/Desktop/Android/GnuTLS/jni/libintl.h:58: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__attribute_format_arg__'
  /home/dazhang/Desktop/Android/GnuTLS/jni/libintl.h:60: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__attribute_format_arg__'
  /home/dazhang/Desktop/Android/GnuTLS/jni/libintl.h:66: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__attribute_format_arg__'
  /home/dazhang/Desktop/Android/GnuTLS/jni/libintl.h:69: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__attribute_format_arg__'
  /home/dazhang/Desktop/Android/GnuTLS/jni/libintl.h:76: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__attribute_format_arg__'
  /home/dazhang/Desktop/Android/GnuTLS/jni/libintl.h:82: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__attribute_format_arg__'
  /home/dazhang/Desktop/Android/GnuTLS/jni/libintl.h:89: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__attribute_format_arg__'
  /home/dazhang/Desktop/Android/GnuTLS/jni/libintl.h:95: error: storage class specified for parameter 'textdomain'
  /home/dazhang/Desktop/Android/GnuTLS/jni/libintl.h:100: error: storage class specified for parameter 'bindtextdomain'
  /home/dazhang/Desktop/Android/GnuTLS/jni/libintl.h:105: error: storage class specified for parameter 'bind_textdomain_codeset'
  In file included from /home/dazhang/Desktop/Android/GnuTLS/jni/libintl.h:116,
                   from /home/dazhang/Desktop/Android/GnuTLS/jni/gl/gettext.h:25,
                   from /home/dazhang/Desktop/Android/GnuTLS/jni/gl/version-etc.c:32:
  /home/dazhang/Desktop/android-ndk-r7b/platforms/android-14/arch-arm/usr/include/locale.h:35: warning: empty declaration
  /home/dazhang/Desktop/android-ndk-r7b/platforms/android-14/arch-arm/usr/include/locale.h:52: error: storage class specified for parameter 'setlocale'
  /home/dazhang/Desktop/android-ndk-r7b/platforms/android-14/arch-arm/usr/include/locale.h:55: warning: empty declaration
  In file included from /home/dazhang/Desktop/Android/GnuTLS/jni/gl/version-etc.c:32:
  /home/dazhang/Desktop/Android/GnuTLS/jni/gl/gettext.h:151: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
  /home/dazhang/Desktop/Android/GnuTLS/jni/gl/gettext.h:171: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
  /home/dazhang/Desktop/Android/GnuTLS/jni/gl/gettext.h:210: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
  /home/dazhang/Desktop/Android/GnuTLS/jni/gl/gettext.h:256: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
  /home/dazhang/Desktop/Android/GnuTLS/jni/gl/version-etc.c:41: warning: empty declaration
  /home/dazhang/Desktop/Android/GnuTLS/jni/gl/version-etc.c:66: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
  /home/dazhang/Desktop/Android/GnuTLS/jni/gl/version-etc.c:183: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
  /home/dazhang/Desktop/Android/GnuTLS/jni/gl/version-etc.c:199: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
  /home/dazhang/Desktop/Android/GnuTLS/jni/gl/version-etc.c:230: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
  /home/dazhang/Desktop/Android/GnuTLS/jni/gl/version-etc.c:240: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
  /home/dazhang/Desktop/Android/GnuTLS/jni/libintl.h:52: error: old-style parameter declarations in prototyped function definition
  /home/dazhang/Desktop/Android/GnuTLS/jni/gl/version-etc.c:258: error: expected '{' at end of input
  make: *** [/home/dazhang/Desktop/Android/GnuTLS/obj/local/armeabi/objs/GnuTLS/gl/version-etc.o] Error 1
  </code></pre>
  
  <p>Is there something wrong with what I'm doing now? Do I need to change anything so that <code>ndk-build</code> is able to compile?</p>
  
  <p><strong>EDIT 2:</strong>
  Lines 53, 58 and 60 are as the following:</p>
  
  <pre><code>49 /* Look up MSGID in the current default message catalog for the current
  50   LC_MESSAGES locale.  If not found, returns MSGID itself (the default
  51   text).  */
  52 extern char *gettext (__const char *__msgid)
  53     __THROW __attribute_format_arg__ (1);
  54
  55 /* Look up MSGID in the DOMAINNAME message catalog for the current
  56   LC_MESSAGES locale.  */
  57 extern char *dgettext (__const char *__domainname, __const char *__msgid)
  58     __THROW __attribute_format_arg__ (2);
  59 extern char *__dgettext (__const char *__domainname, __const char *__msgid)
  60     __THROW __attribute_format_arg__ (2);
  </code></pre>