0

I am trying to run the following code:

#pragma cling add_library_path("/usr/lib/x86_64-linux-gnu")
#pragma cling add_include_path("/usr/include")
#pragma cling add_include_path("/usr/include/x86_64-linux-gnu")
#pragma cling load("/usr/lib/x86_64-linux-gnu/libgmp.so")
#pragma cling load("/usr/lib/x86_64-linux-gnu/libgmpxx.so")
#include <gmpxx.h>

and I get following errors:

In file included from input_line_8:1:
In file included from /usr/include/gmpxx.h:44:
In file included from /usr/include/x86_64-linux-gnu/gmp.h:56:
In file included from /usr/include/limits.h:26:
/usr/include/x86_64-linux-gnu/bits/libc-header-start.h:56:5: error: function-like macro '__GLIBC_USE' is not defined
#if __GLIBC_USE (IEC_60559_BFP_EXT) || __GLIBC_USE (ISOC2X)
    ^
/usr/include/x86_64-linux-gnu/bits/libc-header-start.h:73:5: error: function-like macro '__GLIBC_USE' is not defined
#if __GLIBC_USE (IEC_60559_FUNCS_EXT) || __GLIBC_USE (ISOC2X)
    ^
In file included from input_line_8:1:
In file included from /usr/include/gmpxx.h:44:
In file included from /usr/include/x86_64-linux-gnu/gmp.h:56:
/usr/include/limits.h:145:5: error: function-like macro '__GLIBC_USE' is not defined
#if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
    ^

I am trying to include <limits.h> firstly:

#include <limits.h>
#pragma cling add_library_path("/usr/lib/x86_64-linux-gnu")
#pragma cling add_include_path("/usr/include")
#pragma cling add_include_path("/usr/include/x86_64-linux-gnu")
#pragma cling load("/usr/lib/x86_64-linux-gnu/libgmp.so")
#pragma cling load("/usr/lib/x86_64-linux-gnu/libgmpxx.so")
#include <gmpxx.h>

but I still get the error

In file included from input_line_9:1:
In file included from /usr/include/gmpxx.h:44:
In file included from /usr/include/x86_64-linux-gnu/gmp.h:56:
/usr/include/limits.h:145:5: error: function-like macro '__GLIBC_USE' is not defined
#if __GLIBC_USE (IEC_60559_BFP_EXT_C2X)
    ^

How to make <libgmpxx.h> use <limits.h> from xeus-cling, not from /usr/include?

2 Answers2

0
#pragma cling load("libgmpxx.so")
#pragma cling load("libgmp.so")
#include <gmpxx.h>

is enough. The order of system directories is quite fragile, and you got it wrong, but the good news is that they are already searched implicitly in the right order.

Marc Glisse
  • 7,550
  • 2
  • 30
  • 53
  • `input_line_8:1:10: fatal error: 'gmpxx.h' file not found #include ^~~~~~~~~ ` – Филя Усков Feb 08 '22 at 17:03
  • Well, it works on my computer, I don't know what you system is or how you installed xeus-cling. If you installed it with conda, you could try `conda install gmp` in the same environment. – Marc Glisse Feb 08 '22 at 19:42
0

in jupyter:

#include <stddef.h>    /* for size_t */
#include <limits.h>
#define __xeus_cling__
#pragma cling add_library_path("/usr/lib/x86_64-linux-gnu")
#pragma cling add_include_path("/usr/include")
#pragma cling add_include_path("/usr/include/x86_64-linux-gnu")
#pragma cling load("/usr/lib/x86_64-linux-gnu/libgmp.so")
#pragma cling load("/usr/lib/x86_64-linux-gnu/libgmpxx.so")
#include <gmpxx.h>

and in /usr/include/x86_64-linux-gnu/gmp.h

  #include <stddef.h>    /* for size_t */
  #include <limits.h>

replace with

#ifndef __xeus_cling__
  #include <stddef.h>    /* for size_t */
  #include <limits.h>
#endif
  • 1
    Your main issue is that gmpxx.h is not in the default include path of your compiler, it is in /usr/include, and you can't add `/usr/include` to the include path without causing trouble because of all the other headers in there. If xeus-cling had the equivalent of `-idirafter`, that would be nice, but I don't see it. The easiest workaround is to create a new directory `/some/where/my/include`, add this one to the include path, and create symbolic links to whatever you need in there (gmpxx.h and gmp.h). – Marc Glisse Feb 08 '22 at 19:47