I am trying to use the GMP library in my C program as follows:
/* gmp test */
#include <gmpxx.h>
main() {
printf("yay, it works!\n");
}
and I am compiling this on Linux with gcc -o a.out my-c-program.c
, but I get this error when compiling the #include <gmpxx.h>
line above:
gcc -o a.out my-c-program.c
In file included from my-c-program.c:2:0:
/usr/include/gmpxx.h:34:18: fatal error: iosfwd: No such file or directory
compilation terminated.
Compilation exited abnormally with code 1 at Thu May 5 11:34:16
I looked at the gmpxx.h
file under /usr/include/gmpxx.h
, and on line 34, there is the line #include <iosfwd>
, which explains the error. But how do I fix it? Am I missing a library? Or am I missing something in my gcc
command?
The correct header name for GMP as C library is gmp.h
.
The gmpxx.h
is suited for GMP's C++ Class Interface, which is built on top of gmp.h
and requires to compile with C++ compiler such as g++
.