jupyter-xeus / xeus-cling

Jupyter kernel for the C++ programming language
BSD 3-Clause "New" or "Revised" License
3.01k stars 294 forks source link

gmp print functions don't print in xeus cling #508

Open FeelUsM opened 6 months ago

FeelUsM commented 6 months ago

I run next con in xeus-cling:

#pragma cling load("libgmp.so")
#include <gmp.h>
    mpz_t n;
    int l;

    mpz_init(n);
    mpz_set_ui(n,1);

    mpz_add_ui(n,n,1);

    fprintf(stdout,"n = ");
    l = mpz_out_str(stdout,10,n); // stdout stay unchanged here
    fprintf (stdout,"; (%d)\n",l);

    l = gmp_printf("n = %Zd", n) ; // stdout stay unchanged here
    fprintf (stdout,"; (%d)\n",l);

    char buf[1024];
    l = gmp_sprintf(buf,"%Zd",n);
    printf ("n = %s; (%d)\n",buf,l);

    printf("%s\n",gmp_version);

and it print

n = ; (1)
; (5)
n = 2; (1)
6.2.1

The same code compiled by gcc prints OK:

n = 2; (1)
n = 2; (5)
n = 2; (1)
6.2.1

I assume it because it use different libraries
xeus 3.1.4 h06414e2_0 conda-forge, xeus-cling 0.15.3 he80cb83_2 conda-forge:
/home/username/miniforge3/envs/cling/include/gmp.h /home/username/miniforge3/envs/cling/lib/libgmp.so
gcc (GCC) 13.2.1 20231205 (Red Hat 13.2.1-6): /usr/include/gmp.h /lib64/libgmp.so
but it don't solve the problem