GMP, C++ and extern "C"

Emmanuel Thomé Emmanuel.Thome at normalesup.org
Mon Nov 20 11:55:25 CET 2006


On Sun, Nov 19, 2006 at 10:15:25PM +0100, Niels Möller wrote:
> Hi,
> 
> I have a pure C library, nettle, that uses GMP. To use it from within
> a C++ program, the recommended way is to wrap the inclusion of any
> nettle header files within extern "C", for example
> 
>   extern "C" {
>   #include <nettle/rsa.h>
>   }

this is likely to fail unless you have full control of the header file
you include, because of the failures you mention.

The ``recommended'' way of doing things is:
-- use cc/gcc/*cc to compile a C program
-- use c++/g++/... to compile a C++ program

and have your header files follow this pattern

	#include your-include-files

	#idef	__cplusplus
	extern "C" {
	#endif

	declare some functions to be provided for C linkage.

	#if defined (__cplusplus)
	}
	#endif

	and if needed:
	#if defined (__cplusplus)
	provide some more C++-only stuff. This MUST be outside
	extern "C" blocks.
	#endif

Modify nettle.h that way, I suspect your life will be easier.

E.


More information about the gmp-bugs mailing list