如何将 libgmp 包含到 xeus-cling?

How to include libgmp to 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>

我收到以下错误:

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)
    ^

我想首先包括 <limits.h>:

#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>

但我仍然收到错误

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)
    ^

如何让 <libgmpxx.h> 使用来自 xeus-cling 的 <limits.h>,而不是来自 /usr/include

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

够了。系统目录的顺序很脆弱,你弄错了,但好消息是它们已经按照正确的顺序隐式搜索了。

在 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>

和 在 /usr/include/x86_64-linux-gnu/gmp.h

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

替换为

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