Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation failure when including qqbar.h from within C++ #2049

Closed
SManecke opened this issue Aug 18, 2024 · 1 comment
Closed

Compilation failure when including qqbar.h from within C++ #2049

SManecke opened this issue Aug 18, 2024 · 1 comment

Comments

@SManecke
Copy link

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)

@albinahlback
Copy link
Collaborator

Yes, seems to be correct in what you say. Would you mind opening a PR for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants