Hi Niels!
On Sun, Nov 19, 2006 at 06:42:14PM +0100, Niels Möller wrote:
Jeronimo Pellegrini pellegrini@mpcnet.com.br writes:
But rsa.h includes gmp.h, and unfortunately, this won't work for C++ (at least not for g++) -- not even if declared 'extern "C"'. The <gmpxx.h> header should be used when using GMP from C++ programs.
That sounds kind of broken. The way I understand it, to use the C++ interface to GMP, you should include gmpxx.h, but if you want to use the plain old C interface from within a C++ program, then you should be able to use gmp.h from C++ programs.
What error messages do you get? This really sounds like a bug in gmp or in the gmp installation.
/usr/include/gmp.h:2129: error: declaration of C function 'std::ostream& operator<<(std::ostream&, const __mpq_struct*)' conflicts with /usr/include/gmp.h:2128: error: previous declaration 'std::ostream& operator<<(std::ostream&, const __mpz_struct*)' here /usr/include/gmp.h:2130: error: declaration of C function 'std::ostream& operator<<(std::ostream&, const __mpf_struct*)' conflicts with /usr/include/gmp.h:2129: error: previous declaration 'std::ostream& operator<<(std::ostream&, const __mpq_struct*)' here /usr/include/gmp.h:2132: error: declaration of C function 'std::istream& operator>>(std::istream&, __mpq_struct*)' conflicts with /usr/include/gmp.h:2131: error: previous declaration 'std::istream& operator>>(std::istream&, __mpz_struct*)' here /usr/include/gmp.h:2133: error: declaration of C function 'std::istream& operator>>(std::istream&, __mpf_struct*)' conflicts with /usr/include/gmp.h:2132: error: previous declaration 'std::istream& operator>>(std::istream&, __mpq_struct*)' here
And this is, in gmp.h:
__GMP_DECLSPEC_XX std::ostream& operator<< (std::ostream &, mpz_srcptr); __GMP_DECLSPEC_XX std::ostream& operator<< (std::ostream &, mpq_srcptr); __GMP_DECLSPEC_XX std::ostream& operator<< (std::ostream &, mpf_srcptr); __GMP_DECLSPEC_XX std::istream& operator>> (std::istream &, mpz_ptr); __GMP_DECLSPEC_XX std::istream& operator>> (std::istream &, mpq_ptr); __GMP_DECLSPEC_XX std::istream& operator>> (std::istream &, mpf_ptr);
It seems that we can't include that line in gmp.h if you include it as extern "C".
It would be nice if we could call Nettle's rsa.h from C++. It would work with an #if:
The intention is that
extern "C" { #include <nettle/rsa.h> }
Yes... But for some reason, this works in C++:
#include <gmp.h>
And this doesn't:
extern "C" { #include <gmp.h> }
If there is interest, I could make a patch with either of these two solutions.
First, please investigate why including gmp.h fails.
It has been suggested earlier that Nettle's include files should contain their own C++ guards. The main reason I haven't done that, is that I don't personally use C++, and I don't have any testcases for Nettle and C++. So test cases would be the first requirement for explicit C++ support in Nettle.
Right...
Well, I found a (strange) solution to this.
#include <gmpxx.h>
extern "C" { #include <nettle/rsa.h> }
Seems to work, since gmpxx.h will include (properly) gmp.h.
Maybe just a note on the Nettle documentation would be nice? :-)
PS. Sorry for the late reply, it's caused by a combination of computer problems and child birth ;-)
Congratulations! :-)
J.