flint
flint copied to clipboard
Compilation failure when including `qqbar.h` from within C++
In qqbar.h the extern "C" block is opened before including further headers, like this:
#ifdef __cplusplus
extern "C" {
#endif
#include "fmpz_types.h"
#include "fmpq_types.h"
#include "mpoly_types.h"
#include "acb.h"
This causes a compilation error for me:
#include <flint/qqbar.h>
int main() { return 0; }
In file included from /usr/include/c++/14/bits/stringfwd.h:40,
from /usr/include/c++/14/iosfwd:41,
from /usr/include/x86_64-linux-gnu/gmp.h:35,
from /usr/include/flint/flint.h:28,
from /usr/include/flint/fmpz_types.h:15,
from /usr/include/flint/qqbar.h:25,
from main.cc:3:
/usr/include/c++/14/bits/memoryfwd.h:64:3: error: template with C linkage
64 | template<typename>
| ^~~~~~~~
/usr/include/flint/qqbar.h:22:1: note: ‘extern "C"’ linkage started here
22 | extern "C" {
| ^~~~~~~~~~
The issue is that gmp.h will include C++-only headers if __cplusplus is defined, which will break the compilation since they are inside the extern "C" block. The easy fix is to switch the order to:
#include "fmpz_types.h"
#include "fmpq_types.h"
#include "mpoly_types.h"
#include "acb.h"
#ifdef __cplusplus
extern "C" {
#endif
The same issue occurs in fexpr.h, fexpr_builtin.h and fmpz_mpoly_q.h. If you want, I can create a PR for this.
(As a workaround, if you also encouter this, simply include flint.h before qqbar.h)
Yes, seems to be correct in what you say. Would you mind opening a PR for this?