I'm using Cygwin with gcc and I'm trying to run a quick sample program that uses mpfr library and I have this line of code:
mpfr_out_str (stdout, 10, 0, s, MPFR_RNDD);
And I'm getting this compiler warning.
main.c: In function ‘main’:
main.c:21:5: warning: implicit declaration of function ‘mpfr_out_str’; did you mean ‘mpf_out_str’? [-Wimplicit-function-declaration]
mpfr_out_str (stdout, 10, 0, s, MPFR_RNDD);
^~~~~~~~~~~~
mpf_out_str
Yet when I looked online at various sites for simple examples of use and even looked though the mpfr docs they were all using
mpfr_out_str(...)
...
So why is the compiler complaining to me that I should be using
mpf_out_str
Instead?
--- main.c --- online example
#include <stdio.h>
#include "gmp.h"
#include "mpfr.h"
int main() {
unsigned int i;
mpfr_t s, t, u;
mpfr_init2 (t, 200);
mpfr_set_d (t, 1.0, MPFR_RNDD);
mpfr_init2 (s, 200);
mpfr_set_d (s, 1.0, MPFR_RNDD);
mpfr_init2 (u, 200);
for ( i = 1; i <= 100; i++ ) {
mpfr_mul_ui (t, t, i, MPFR_RNDU);
mpfr_set_d (u, 1.0, MPFR_RNDD);
mpfr_div (u, u, t, MPFR_RNDD);
mpfr_add (s, s, t, MPFR_RNDD);
}
printf( "Sum is " );
mpfr_out_str (stdout, 10, 0, s, MPFR_RNDD); // this line here
putchar ('\n');
mpfr_clear(s);
mpfr_clear(t);
mpfr_clear(u);
return 0;
}
Also for some reason I think Cygwin with gcc is having issues linking against gmp and mprf... I'm using gcc version 7.3.0 (GCC).
Note: In my main.c I originally had the includes the same as the online example:
#include <...>
I previously mentioned that I had trouble linking against the library and tried hundreds of different ways to try and link against them, too many to list here. So eventually I took a copy of the libs and their headers and just pasted them directly into the same folder that contains main.c and this is why you see my includes as
#include "..."
instead of the original online sample.
Mind you I'm not all that familiar with Unix-POSIX
environment, operations or command line arguments for compiling c/c++ code on a Unix environment that uses either gcc/g++ or clang. I've primarily been accustomed to Visual Studio, windows and cmd and it's features, settings and syntax. Right now I'm learning as I go from documentation, websites, online tutorials both text & video, etc.
This may be a topic of discussion for a different question, but I think that it might relate into partially answering this posted question.
When one installs Cygwin and then decides to install gcc/g++ as opposed to mingw's clang; should gmp and mpir already be installed or do they have to be installed manually and if so: in what order? Does gmp & mpir need to be installed before gcc or can it be installed after? Does the order make a difference in how gcc is able to link against such libraries? Would the proper installation order and linking of libraries resolve this compiler warning?