I’m trying to integrate the Gnutls Example from GnuTLS Doc in a C++ class.
Unfortunatly it throws Undefined references while linking with g++.
So I tryed to compile the Example (Its in pure C) without changes with g++, but no success.
It works if I use the gcc.
tino@develeee:~/Code/tlstests$ gcc tlsclient.c -lgnutls
/tmp/ccBqJdQr.o: In function `main':
tlsclient.c:(.text+0x3d0): undefined reference to `tcp_connect'
tlsclient.c:(.text+0x58d): undefined reference to `tcp_close'
collect2: ld returned 1 exit status
tino@develeee:~/Code/tlstests$ g++ tlsclient.c -lgnutls
/tmp/ccRq5DcT.o: In function `load_keys()':
tlsclient.c:(.text+0x186): undefined reference to gnutls_pcert_import_x509_raw(gnutls_pcert_st*, gnutls_datum_t const*, gnutls_x509_crt_fmt_t, unsigned int)'
tlsclient.c:(.text+0x299): undefined reference to gnutls_privkey_init(gnutls_privkey_st**)'
tlsclient.c:(.text+0x2b5): undefined reference to `gnutls_privkey_import_x509(gnutls_privkey_st*, gnutls_x509_privkey_int*, unsigned int)'
/tmp/ccRq5DcT.o: In function `main':
tlsclient.c:(.text+0x37e): undefined reference to `gnutls_certificate_set_retrieve_function2(gnutls_certificate_credentials_st*, int (*)(gnutls_session_int*, gnutls_datum_t const*, int, gnutls_pk_algorithm_t const*, int, gnutls_pcert_st**, unsigned int*, gnutls_privkey_st**))'
tlsclient.c:(.text+0x3d6): undefined reference to `tcp_connect()'
tlsclient.c:(.text+0x594): undefined reference to `tcp_close(int)'
collect2: ld returned 1 exit status
You can see that only functions which a declarated in gnutls/abstract.h are unefined using the C++ Compiler. (Ignore the undefined references to tcp_connect() and tcp_close(), they are simply not defined and declared extern)
I thougt C++ is C plus classes and Templates? So I can’t imagin, why I got these Errors.
Did anybody had something like this before?
Wrap your headers in
extern "C" {}block. It looks likegnutls/abstract.his included as C++ header.