relic-toolkit / relic

Code
Other
453 stars 179 forks source link

Wrap headers with extern "C" for C++ compatibility #234

Closed ghoshbishakh closed 12 months ago

ghoshbishakh commented 2 years ago

The headers are not wrapped with extern "C" {} , which causes major problems when using with a C++ project. An example follows:

extern "C" {
#include <relic/relic.h>
}

This code internally also includes gmp. (if relic is built with gmp). Now, since it is a c++ code, #ifdef __cplusplus segments are enabled causing it to import some C++ specific codes (specifically templates).

A hack I am using is to import gmp above that. Once it is imported, the header guards prevent relic to reimport it and thus avoiding the error :)

@abhimp suggested to wrap each relic header file with extern "C". Example: https://github.com/relic-toolkit/relic/blob/9206ae50b667de160fcc385ba3dc2c920143ab0a/src/md/blake2.h#L27-L29

If you @dfaranha give the green signal I will work on this next week.

dfaranha commented 2 years ago

Green signal! Please submit a Pull Request :)